C# Chart新建图表

发布时间 2023-05-31 11:02:56作者: 浑浑噩噩一只小迷七

1、新建Chart

2、把名字位置改到上方

3、操作

chartRes.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet; //设置网格类型为虚线
chartRes.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dot; //设置网格类型为虚线

chartRes.ChartAreas[0].AxisX.Interval = 10; //X轴数值间隔
chartRes.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
chartRes.ChartAreas[0].AxisX.LabelStyle.Angle = -30; //X轴数据的角度
chartRes.Series[0].ChartType = SeriesChartType.Line; //图表类型为曲线

chartRes.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal; //文本方向为水平

chartRes.Series[0].Points.DataBindXY(x, y);  // 绑定数据

chartRes.Series[0].Label = "(#VALX℃:#VALMpa)";  // 设置显示X Y的值  
chartRes.ChartAreas[0].AxisY.Title = "压力(MPa)";
chartRes.ChartAreas[0].AxisX.Title = "温度(℃)";
chartRes.Series[0].LegendText = "温度-压力曲线";

string fullFileName = @"../../Docs/111.png";
chartRes.SaveImage(fullFileName, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Png); //保存曲线图

fullFileName= Path.GetFullPath(fullFileName.ToString()); //根据相对路径获取绝对路径