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);
#endregion
List<Series> list = new List<Series>() { 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);
}
/// <summary>
/// 根据数据创建一个图形展现
/// </summary>
/// <param name="caption">图形标题</param>
/// <param name="viewType">图形类型</param>
/// <param name="dt">数据DataTable</param>
/// <param name="rowIndex">图形数据的行序号</param>
/// <returns></returns>
private Series CreateSeries(string caption, ViewType viewType, DataTable dt, int rowIndex)
{
Series series = new Series(caption, viewType);
for (int i = 1; i < dt.Columns.Count; i++)
{
int argument = Int32.Parse(dt.Columns[i].ColumnName);//参数名称
String value = (String)dt.Rows[rowIndex][i];//参数值
series.Points.Add(new SeriesPoint(argument, value));
}
series.ArgumentScaleType = ScaleType.Qualitative;
return series;
}
dev ChartControl折线图,曲线图
最新推荐文章于 2021-11-27 05:29:45 发布