作者:海纳百川2602902033 | 来源:互联网 | 2023-09-05 14:55
privatevoidCreateChart(DataTabledt){this.panel1.Controls.Clear();ChartControlspineChartnew
private void CreateChart(DataTable dt){this.panel1.Controls.Clear();ChartControl spineChart = new ChartControl();#region Series//创建几个图形的对象Series series1 = CreateSeries("SCL", ViewType.Line, dt, 0);Series series2 = CreateSeries("SCE", ViewType.Line, dt, 1);#endregionList list = new List() { series1, series2 };spineChart.Series.AddRange(list.ToArray());XYDiagram diagram = (XYDiagram)spineChart.Diagram;diagram.AxisX.Title.Visible = true;diagram.AxisX.Title.Alignment = StringAlignment.Center;diagram.AxisX.Title.Text = "波长(入)";diagram.AxisX.Title.Antialiasing = true;diagram.AxisX.Title.Font = new Font("Tahoma", 12, FontStyle.Bold);diagram.AxisX.GridSpacing = 60;diagram.AxisY.Title.Visible = true;diagram.AxisY.Title.Alignment = StringAlignment.Center;diagram.AxisY.Title.Text = "反射率(%)";diagram.AxisY.Title.Antialiasing = true;diagram.AxisY.Title.Font = new Font("Tahoma", 12, FontStyle.Bold);diagram.AxisY.GridSpacing = 1;diagram.EnableAxisXScrolling = false;diagram.EnableAxisYScrolling = false;diagram.EnableAxisXZooming = false;diagram.EnableAxisYZooming = false;((XYDiagram)spineChart.Diagram).EnableAxisXZooming = true;spineChart.Titles.Add(new ChartTitle());spineChart.Titles[0].Text = "光谱图形";spineChart.Titles[0].Font = new Font("Tahoma", 14, FontStyle.Bold);spineChart.Dock = DockStyle.Fill;this.panel1.Controls.Add(spineChart);}/// /// 根据数据创建一个图形展现/// /// 图形标题/// 图形类型/// 数据DataTable/// 图形数据的行序号/// private Series CreateSeries(string caption, ViewType viewType, DataTable dt, int rowIndex){Series series = new Series(caption, viewType);for (int i = 1; i