C# Chart控件

Chart 画柱形图,环形图,折线图

chart图形显示

chart1.Series[Prod].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Doughnut;//环形图
chart1.Series[Prod].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;//柱形图
 chart1.Series[Prod].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;//线段          

chart 属性
是否显示双Y轴

chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;//启用Y2
this.chart1.ChartAreas[0].AxisY2.Maximum = 100;//设置Y2最大值
this.chart1.ChartAreas[0].AxisY2.Title = Mes.Core.Utility.StrUtil.Translate(Ytitle); 
this.chart1.Series[Prod].YAxisType = AxisType.Secondary;//将series的值与Y2联系

设置坐标轴刻度字体大小

chart1.ChartAreas[0].AxisY.TitleFont = new Font("宋体", 8F);//坐标轴标题字体大小
chart1.ChartAreas[0].AxisX.TitleFont = new Font("宋体", 8F);
chart1.ChartAreas[0].AxisY2.TitleFont = new Font("宋体", 8F);
chart1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("宋体", 8F);//坐标轴刻度字体大小
chart1.ChartAreas[0].AxisY.LabelStyle.Font = new Font("宋体", 8F);
chart1.ChartAreas[0].AxisY2.LabelStyle.Font = new Font("宋体", 8F);

设置Chart标题

 public void SetChartTitle(string Title)
        {
            this.chart1.Titles.Add(Title);        
        }

取消X/Y辅助线

 this.chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
            this.chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
            this.chart1.ChartAreas[0].AxisX2.MajorGrid.Enabled = false;
            this.chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;

设置X/Y名称

  public void SetChartName(string XTitle, string Ytitle)
        {
            this.chart1.ChartAreas[0].AxisX.Title = Mes.Core.Utility.StrUtil.Translate(XTitle);
            this.chart1.ChartAreas[0].AxisY.Title = Mes.Core.Utility.StrUtil.Translate(Ytitle);
        }
上一篇:Chart控件Legend自定义


下一篇:winform 绘图控件 chart 实时曲线图