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 >}