Use owc to generate data analysis charts

Source: Internet
Author: User
First, add reference ---- com -----> Microsoft Office Web Components on the vs2005 ---- website ----

Private   Void Getchart (datatable DT, int rows)
{
Try
{
Int Count = DT. Rows. count; If (count <3)
{
Divchart. innerhtml = "<span style = 'color: red'> no more than three pieces of data can be generated! </Span> "; Return;
}
// Monthly Storage
String [] Monnum =   New   String [Count];
// Store Data
String [] Moncount =   New   String [Count];
String [] Moncount1 =   New   String [Count];
// Assign values to Arrays
For ( Int I =   0 ; I < Count; I ++ )
{
Monnum [I] = DT. Rows [I] [ 3 ]. Tostring ();
Moncount [I] = DT. Rows [I] [ 1 ]. Tostring ();
Moncount1 [I] = DT. Rows [I] [ 2 ]. Tostring ();
}
String Strxdata = String. empty;
Foreach ( String Strdata In Monnum)
{
Strxdata + = Strdata +   " \ T " ;
}
String Strydata = String. empty;
Foreach ( String Strvalue In Moncount)
{
Strydata + = Strvalue +   " \ T " ;
}

String Strydata1 = String. empty;
Foreach ( String Strvalue In Moncount1)
{
Strydata1 + = Strvalue +   " \ T " ;
}

Chartspace layspace= NewChartspaceclass ();

Chchart insertchart=Layspace. charts. Add (0);

Insertchart. Type=Chartcharttypeenum. chcharttypebarclustered;

String Type =   " 1 " ;
If (Request. querystring [ " Type " ] ! =   Null )
{
Type = Request. querystring [ " Type " ]. Tostring ();
}

Insertchart. haslegend= True;
Insertchart. hastitle= True;
Insertchart. Title. Caption= "Sales records";

Insertchart. Axes [0 ]. Hastitle =   True ;
Insertchart. Axes [ 0 ]. Title. Caption =   String . Format ( " Date ({0 }) " , Type =   " 1 "   ?   " Day " : " Month " );

// Scale format

Insertchart. Axes [ 1 ]. Hastitle =   True ;
Insertchart. Axes [ 1 ]. Scaling. splitminimum =   200 ;
Insertchart. Axes [ 1 ]. Title. Caption =   " Amount (RMB) " ;

Insertchart. seriescollection. Add ( 0 );
Insertchart. seriescollection [ 0 ]. Datalabelscollection. Add ();
Insertchart. seriescollection [ 0 ]. Datalabelscollection [ 0 ]. Hasvalue =   True ;
Insertchart. seriescollection [ 0 ]. Setdata (chartdimensionsenum. chdimseriesnames, + ( Int ) Chartspecialdatasourcesenum. chdataliteral, " Total sales " );
Insertchart. seriescollection [ 0 ]. Setdata (chartdimensionsenum. chdimcategories, + ( Int ) Chartspecialdatasourcesenum. chdataliteral, strxdata );
Insertchart. seriescollection [ 0 ]. Setdata (chartdimensionsenum. chdimvalues ,( Int ) Chartspecialdatasourcesenum. chdataliteral, strydata );

Insertchart. Axes [ 0 ]. Groupingtype = Owc10.chartaxisgroupingenum. chaxisgroupingmanual;
Insertchart. Axes [ 0 ]. Groupingunittype = Chartaxisunittypeenum. chaxisunitmonth;
Insertchart. Axes [ 0 ]. Numberformat =   " Yyyy-mm " ;
Insertchart. Axes [ 0 ]. Groupingunit =   1 ;

Insertchart. seriescollection. Add ( 1 );
Insertchart. seriescollection [ 1 ]. Datalabelscollection. Add ();
Insertchart. seriescollection [ 1 ]. Datalabelscollection [ 0 ]. Hasvalue =   True ;
Insertchart. seriescollection [ 1 ]. Setdata (chartdimensionsenum. chdimseriesnames, + ( Int ) Chartspecialdatasourcesenum. chdataliteral, " Consumed " );
Insertchart. seriescollection [ 1 ]. Setdata (chartdimensionsenum. chdimcategories, + ( Int ) Chartspecialdatasourcesenum. chdataliteral, strxdata );
Insertchart. seriescollection [ 1 ]. Setdata (chartdimensionsenum. chdimvalues ,( Int ) Chartspecialdatasourcesenum. chdataliteral, strydata1 );

String FN = Datetime. Now. tostring ( " Yyyymmddhhmmss " ) +   " . Gif " ;
String Strabsolutepath = (Server. mappath (config. temp_path )) + FN;
Int Height = rows * (rows> 10? 30: 50); // data width
Layspace. exportpicture (strabsolutepath, "GIF", 660, height ); Divchart. innerhtml =   " "   + FN +   " '> " ;
}
Catch (exception ex)
{< br> console. write (ex. message);
}< BR >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.