c# chart 控件 曲线图
c# chart 控件 曲线图SeriesChartType.Line 折线 SeriesChartType.Spline 曲线usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.Windows.Forms.DataVisualization.Charting;namespaceWindowsApp{publicpartialclassFormMain:Form{publicFormMain(){InitializeComponent();}/// summary/// 折线图/// /summary/// param namesender/param/// param namee/paramprivatevoidbtnLine_Click(objectsender,EventArgse){// 列表ListintListPointnewListint();RandomrandomnewRandom();intnum0;for(inti0;i10;i){numrandom.Next(0,10);// 随机数ListPoint.Add(num);}// 清除所有 节点chartLine.Series[0].Points.Clear();for(inti0;iListPoint.Count;i){// 增加 节点chartLine.Series[0].Points.AddXY(i1,ListPoint[i]);}}/// summary/// 折线图/饼图/// /summary/// param namesender/param/// param namee/paramprivatevoidbtnPie_Click(objectsender,EventArgse){string[]xnewstring[]{1月,2月,3月,4月,5月};double[]ynewdouble[]{500,900,700,650,450};// 标题chartView.Titles.Add(折线范例);chartView.Titles[0].ForeColorColor.Blue;chartView.Titles[0].FontnewFont(微软雅黑,12f,FontStyle.Regular);chartView.Titles[0].AlignmentContentAlignment.TopCenter;chartView.Titles.Add(右标题);chartView.Titles[1].ForeColorColor.Blue;chartView.Titles[1].FontnewFont(微软雅黑,8f,FontStyle.Regular);chartView.Titles[1].AlignmentContentAlignment.TopRight;// 控件背景chartView.BackColorColor.Transparent;// 图表区背景chartView.ChartAreas[0].BackColorColor.Transparent;chartView.ChartAreas[0].BorderColorColor.Transparent;// X轴标签间距chartView.ChartAreas[0].AxisX.Interval1;chartView.ChartAreas[0].AxisX.LabelStyle.IsStaggeredtrue;chartView.ChartAreas[0].AxisX.LabelStyle.Angle-30;chartView.ChartAreas[0].AxisX.TitleFontnewFont(微软雅黑,14f,FontStyle.Regular);chartView.ChartAreas[0].AxisX.TitleForeColorColor.Black;// X坐标轴颜色//chartView.ChartAreas[0].AxisX.LineColor ColorTranslator.FromHtml(#808080);chartView.ChartAreas[0].AxisX.LabelStyle.ForeColorColor.Black;chartView.ChartAreas[0].AxisX.LabelStyle.FontnewFont(微软雅黑,10f,FontStyle.Regular);// X坐标轴标题chartView.ChartAreas[0].AxisX.Title月份;chartView.ChartAreas[0].AxisX.TitleFontnewFont(微软雅黑,10f,FontStyle.Regular);chartView.ChartAreas[0].AxisX.TitleForeColorColor.Black;chartView.ChartAreas[0].AxisX.TextOrientationTextOrientation.Horizontal;// X轴网络线条chartView.ChartAreas[0].AxisX.MajorGrid.Enabledtrue;//chartView.ChartAreas[0].AxisX.MajorGrid.LineColor ColorTranslator.FromHtml(#E6E6FA);// Y坐标轴颜色//chartView.ChartAreas[0].AxisY.LineColor ColorTranslator.FromHtml(#808080);chartView.ChartAreas[0].AxisY.LabelStyle.ForeColorColor.Black;chartView.ChartAreas[0].AxisY.LabelStyle.FontnewFont(微软雅黑,10f,FontStyle.Regular);// Y坐标轴标题chartView.ChartAreas[0].AxisY.Title数量(台);chartView.ChartAreas[0].AxisY.TitleFontnewFont(微软雅黑,10f,FontStyle.Regular);chartView.ChartAreas[0].AxisY.TitleForeColorColor.Black;chartView.ChartAreas[0].AxisY.TextOrientationTextOrientation.Rotated270;chartView.ChartAreas[0].AxisY.ToolTip数量(台);// Y轴网格线条chartView.ChartAreas[0].AxisY.MajorGrid.Enabledtrue;//chartView.ChartAreas[0].AxisY.MajorGrid.LineColor ColorTranslator.FromHtml(#E6E6FA);//chartView.ChartAreas[0].AxisY2.LineColor Color.Transparent;// 背景渐变chartView.ChartAreas[0].BackGradientStyleGradientStyle.None;// 图例样式LegendlegendnewLegend(销量);legend.Title图例;legend.TitleBackColorColor.Transparent;legend.BackColorColor.Transparent;legend.TitleForeColorColor.Black;legend.TitleFontnewFont(微软雅黑,10f,FontStyle.Regular);legend.FontnewFont(微软雅黑,8f,FontStyle.Regular);legend.ForeColorColor.Black;chartView.Series[0].XValueTypeChartValueType.String;// 设置X轴上的值类型chartView.Series[0].Label#VAL;// 设置显示X Y的值chartView.Series[0].LabelForeColorColor.Blue;chartView.Series[0].ToolTip#VALX:#VAL(台);// 鼠标移动到对应点显示数值chartView.Series[0].ChartTypeSeriesChartType.Line;// 图类型 折线Line 饼图 PiechartView.Series[0].ColorColor.SkyBlue;chartView.Series[0].LegendTextlegend.Name;chartView.Series[0].IsValueShownAsLabeltrue;chartView.Series[0].LabelForeColorColor.Black;chartView.Series[0].CustomPropertiesDrawingStyle Cylinder;chartView.Series[0].CustomPropertiesPieLabelStyle Outside;chartView.Legends.Add(legend);chartView.Legends[0].Position.Autotrue;chartView.Series[0].IsValueShownAsLabeltrue;// 是否显示图例chartView.Series[0].IsVisibleInLegendtrue;chartView.Series[0].ShadowOffset0;// 折线//chartView.Series[0][PieLineColor] Blue;// 绑定数据chartView.Series[0].Points.DataBindXY(x,y);chartView.Series[0].Points[0].ColorColor.Black;// 绑定颜色//chartView.Series[0].Palette ChartColorPalette.BrightPastel;}/// summary/// 折线图凸显点/// /summary/// param namesender/param/// param namee/paramprivatevoidbtnLinePoint_Click(objectsender,EventArgse){// 清除所有 节点chartLine.Series[0].Points.Clear();ListstringxnewListstring(){A,B,C,D,E,F,G};ListintynewListint(){10,20,30,40,35,25,15};// 线条颜色chartLine.Series[0].ColorColor.Blue;// 线条粗细chartLine.Series[0].BorderWidth3;// 标记点边框颜色chartLine.Series[0].MarkerBorderColorColor.Black;// 标记点边框大小chartLine.Series[0].MarkerBorderWidth3;// 标记点中心颜色chartLine.Series[0].MarkerColorColor.Red;// 标记点大小chartLine.Series[0].MarkerSize8;// 标记点类型chartLine.Series[0].MarkerStyleMarkerStyle.Square;// 将文字移到外侧chartLine.Series[0][PieLabelStyle]Outside;// 绘制黑色的连线chartLine.Series[0][PieLineColor]Black;chartLine.Series[0].Points.DataBindXY(x,y);}/// summary/// 饼图/// /summary/// param namesender/param/// param namee/paramprivatevoidbtnPieOnly_Click(objectsender,EventArgse){ListstringxnewListstring(){A,B,C,D,E,F,G};ListintynewListint(){10,20,30,40,35,25,15};chartPie.Series[0].ChartTypeSeriesChartType.Pie;// 图类型chartPie.Series[0][PieLabelStyle]Outside;// 将文字移到外侧chartPie.Series[0][PieLineColor]Black;// 绘制黑色的连线chartPie.Series[0].IsValueShownAsLabeltrue;chartPie.Series[0].Points.DataBindXY(x,y);}/// summary/// 柱状图/// /summary/// param namesender/param/// param namee/paramprivatevoidbtnBar_Click(objectsender,EventArgse){// 清除所有 节点chartBar.Series.Clear();//chartBar.Series[0].ChartType SeriesChartType.Bar;// 创建SeriesSeriesanewSeries();a.LegendText柱a;SeriesbnewSeries();b.LegendText柱b;SeriescnewSeries();c.LegendText柱c;// 随机数RandomrnewRandom();for(inti1;i10;i){// 加入集合a.Points.AddXY(i,r.Next(1,9));b.Points.AddXY(i,r.Next(10,20));c.Points.AddXY(i,r.Next(21,30));}// 指定柱形条的颜色a.ColorColor.Green;b.ColorColor.Red;c.ColorColor.Black;// 加入到chartBar中chartBar.Series.Add(a);chartBar.Series.Add(b);chartBar.Series.Add(c);// X轴网格线条chartBar.ChartAreas[0].AxisX.MajorGrid.Enabledfalse;//chartBar.Series[0].LegendText a;//chartBar.Series[1].LegendText b;//chartBar.Series[2].LegendText c;}/// summary/// 散点图/// /summary/// param namesender/param/// param namee/paramprivatevoidbtnPoint_Click(objectsender,EventArgse){// 列表ListintListPointnewListint();RandomrandomnewRandom();intnum0;for(inti0;i10;i){numrandom.Next(0,10);// 随机数ListPoint.Add(num);}// 清除所有 节点chartPoint.Series[0].Points.Clear();for(inti0;iListPoint.Count;i){// 增加 节点chartPoint.Series[0].Points.AddXY(i1,ListPoint[i]);}// 是否显示图例chartPoint.Series[0].IsVisibleInLegendfalse;chartPoint.Series[0].ChartTypeSeriesChartType.Point;// 图类型chartPoint.Series[0].MarkerColorColor.Red;// 标记点中心颜色chartPoint.Series[0].MarkerStyleMarkerStyle.Circle;// 标记点类型}/// summary/// 曲线图/// /summary/// param namesender/param/// param namee/paramprivatevoidbtnSPLine_Click(objectsender,EventArgse){// 列表ListintListPointnewListint();RandomrandomnewRandom();intnum0;for(inti0;i10;i){numrandom.Next(0,10);// 随机数ListPoint.Add(num);}// 清除所有 节点chartSPLine.Series[0].Points.Clear();for(inti0;iListPoint.Count;i){// 增加 节点chartSPLine.Series[0].Points.AddXY(i1,ListPoint[i]);}// 是否显示图例chartSPLine.Series[0].IsVisibleInLegendfalse;chartSPLine.Series[0].ChartTypeSeriesChartType.Spline;// 图类型chartSPLine.Series[0].MarkerColorColor.Red;// 标记点中心颜色chartSPLine.Series[0].MarkerStyleMarkerStyle.Circle;// 标记点类型}}}