c#_ms_chart_控件使用方法汇总(附统计图)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
c# ms chart 控件使用方法
第一个简单的chart:创建曲线图
chart1.Series.Clear();
Series series = new Series("Spline");
series.ChartType = SeriesChartType.Spline;
series.BorderWidth = 3;
series.ShadowOffset = 2;
// Populate new series with data
series.Points.AddY(67);
series.Points.AddY(57);
series.Points.AddY(83);
series.Points.AddY(23);
series.Points.AddY(70);
series.Points.AddY(60);
series.Points.AddY(90);
series.Points.AddY(20);
// Add series into the chart's series collection
chart1.Series.Add(series);
同时显示2条曲线
// Populate series with random data
Random random = new Random();
for (int pointIndex = 0; pointIndex < 10;pointIndex++)
{
Chart1.Series["Series1"].Points.AddY(random.Next(45, 95)); Chart1.Series["Series2"].Points.AddY(random.Next(5, 75)); }
// Set series chart type
Chart1.Series["Series1"].ChartType = SeriesChartType.Line; Chart1.Series["Series2"].ChartType = SeriesChartType.Spline;
// Set point labels
Chart1.Series["Series1"].IsValueShownAsLabel = true;
Chart1.Series["Series2"].IsValueShownAsLabel = true;
// Enable X axis margin
Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true;
// Enable 3D, and show data point marker lines
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; Chart1.Series["Series1"]["ShowMarkerLines"] = "True";
Chart1.Series["Series2"]["ShowMarkerLines"] = "True";
显示column类型图,柱状图
// Create new data series and set it's visual attributes
Chart1.Series.Clear();
Series series = new Series("FlowRead");
series.ChartType = SeriesChartType.Column;
series.BorderWidth = 3;
series.ShadowOffset = 2;
// Populate new series with data
series.Points.AddY(67);
series.Points.AddY(57);
series.Points.AddY(83);
series.Points.AddY(23);
series.Points.AddY(70);
series.Points.AddY(60);
series.Points.AddY(90);
series.Points.AddY(20);
// Add series into the chart's series collection
Chart1.Series.Add(series);
很多点,效率还可以
// Fill series data
double yValue = 50.0;
Random random = new Random();
for (int pointIndex = 0; pointIndex < 20000;pointIndex++)
{
yValue = yValue + (random.NextDouble() * 10.0 - 5.0);
Chart1.Series["Series1"].Points.AddY(yValue);
}
// Set fast line chart type
Chart1.Series["Series1"].ChartType = SeriesChartType.FastLine;
日期,xy类型
// Create a new random number generator
Random rnd = new Random();
// Data points X value is using current date DateTime date = DateTime.Now.Date;
// Add points to the stock chart series
for (int index = 0; index < 10; index++)
{
Chart1.Series["Series1"].Points.AddXY( date, // X value is a date
rnd.Next(40,50)); //Close Y value
// Add 1 day to our X value
date = date.AddDays(1);