C # mschart Learning

Source: Internet
Author: User
I. Description

Mschart data bar chart/line chart

1. Bind Data Based on Time and time points, and display the data as a column chart, line chart
2. Two types of Charts shown in 1 can be dynamically drawn (no ASP. Chart control is required on the page) and displayed on the page.
3. When the cursor is suspended, the time and data of the current coordinate point can be displayed.
4. When you click the mouse, you can get the data value of the x-axis coordinate of the currently clicked coordinate point, and use the script to switch to the new page.
5. Do not use datasource for data binding if the coordinate axis binding time is not consecutive;
After you bind with points. addxy (), there will be no gaps due to time points, so that the two adjacent columns are far apart.

II,

1. line chart

2. Bar Chart

 

3. Create a Ms chart using code
View code

/// <Summary>
/// Set chart Basic Information
/// </Summary>
/// <Param name = "chartname"> </param>
/// <Returns> </returns>
Chart chartsetting (string chartname)
{
Chart newchart = new chart ();

# Region chart properies
Newchart. width = unit. pixel (990 );
Newchart. Height = unit. pixel (160 );
Newchart. backcolor = color. White; // color. fromargb (211,223,240 );
Newchart. ID = chartname;
Newchart. cssclass = "chartinfo ";
Newchart. palette = chartcolorpalette. brightpastel;
// Newchart. borderskin. skinstyle = borderskinstyle. emboss;
# Endregion

# Region chartarea
Chartarea = new chartarea ("chartarea1 ");
Chartarea. borderdashstyle = chartdashstyle. Solid;
Chartarea. backcolor = color. whitesmoke; // color. fromargb (0, 0, 0, 0 );
Chartarea. shadowcolor = color. fromargb (0, 0, 0, 0 );
Chartarea. axisx. majorgrid. linedashstyle = chartdashstyle. Dash; // you can specify a dotted line as the grid.
Chartarea. axisy. majorgrid. linedashstyle = chartdashstyle. Dash;
Newchart. chartareas. Add (chartarea );
# Endregion

# Region Series
Series serdvalue = new series ("serdvalue ");
Serdvalue. chartarea = "chartarea1 ";
Serdvalue. yvaluetype = chartvaluetype. Double;
Serdvalue. labelformat = "0.ms ";
Serdvalue. xvaluetype = chartvaluetype. Auto;
Serdvalue. shadowcolor = color. Black;
Serdvalue. customproperties = "drawingstyle = emboss ";

Newchart. Series. Add (serdvalue );
# Endregion

# Region add and click events
Newchart. Click + = new imagemapeventhandler (newchart_click );
Newchart. attributes ["onclick"] = clientscript. getpostbackeventreference (newchart ,"@"). replace ("'@'", "'chart: '+ _ getcoord (event )");
Newchart. Style [htmltextwriterstyle. position] = "relative ";
# Endregion

Return newchart;
}
4. fill data in MS chart
View code

Public void drawchart ()
{
# Region obtain relevant data based on the cache
Object cachecodedata = datacache. getcache (guid. Next ());
If (cachecodedata! = NULL)
{
Dtdata = cachecodedata as datatable;
}
Else
{
Dtdata = getdatatableinfo (); // get data
// Write the cache again
If (dtdata! = NULL)
{
Datacache. setcache (guid. Next ());
}
}
# Endregion

Series = NULL;
Series = new series ("spline ");
Series. Color = color. fromargb (220, 65,140,240 );

If (rblcharttype. selectedvalue = "0 ")
{
Series. charttype = seriescharttype. Column; // column chart
}
Else
{
Series. charttype = seriescharttype. Line; // line chart
}
Chart newchart = chartsetting (strstationid + "_" + paramcode );
Isshowabnormal = cbabnormalvalue. checked;

If (dsstationdata = NULL)
{
// Title
Newchart. Titles. Add (": no related value ");
}
Else
{
Newchart. Titles. Add (strdefaultdataparamname );
For (INT I = 0; I <dtdata. Rows. Count; I ++)
{
Datarow ROW = dtdata. Rows [I];
String x = row ["datatime"] = NULL? "": Row ["datatime"]. tostring ();
String y = row ["dvalue"] = NULL? "0": Row ["datavalue"]. tostring ();
Series. Points. addxy (x, y );
// Hover the cursor over the display value
Series. Points [I]. tooltip = "detection time = [" + x + "] \ n detection value =" + Y;
// Process the data obtained when the mouse clicks
Series. points [I]. postbackvalue = "series =" + series. name + ", Index = # index, x = # valx, y = # Valy, code =" + strdefadatdataparamname;
}
}
Newchart. chartareas [0]. axisx. Title = "detection time ";
Newchart. chartareas [0]. axisy. Title = "detection value" + "(" + crtddata. getparamunit (paramcode) + ")";
Newchart. Series. Remove (series );
Newchart. Series. Add (series );
// Newchart. Series ["spline"]. mapareaattributes = "onclick = javascript: Alert ('data point with index # index was clicked ')";
Panelchartinfo. Controls. Add (newchart); // Add the chart to the panel control on the ASPX page
}

This article is also published on: eniova blog

Http://www.e6wa.com/Article/202.aspx

Related Article

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.