我有3列数据表;我要在图表上显示INST_ID和Legends的值。
我的问题是,INST_ID可以变化。它可能有5个不同的INST_ID。
如何显示属于INST_ID的所有系列和图例?
这是当前的结果
下面是我为Ultra Data Chart生成的代码
private void Form1_Load(object sender, EventArgs e)
{
dtLineTest.Columns.Add("SAMPLE_TIME",typeof(DateTime));
dtLineTest.Columns.Add("INST_ID", typeof(Int32));
dtLineTest.Columns.Add("VALUE", typeof(Int32));
dtLineTest.Rows.Add(DateTime.Now,1,14);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-1), 1, 18);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-2), 1, 11);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-3), 1, 7);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-4), 1, 21);
dtLineTest.Rows.Add(DateTime.Now, 2, 16);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-1), 2, 3);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-2), 2, 5);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-3), 2, 12);
dtLineTest.Rows.Add(DateTime.Now.AddMinutes(-4), 2, 13);
var xAxis = new CategoryXAxis();
var yAxis = new NumericYAxis();
xAxis.DataSource = dtLineTest;
xAxis.Label = "SAMPLE_TIME";
var legend = new UltraLegend();
var lineSeries = new LineSeries();
lineSeries.DataSource = dtLineTest;
lineSeries.ValueMemberPath = "VALUE";
lineSeries.Title = "INST_ID";
lineSeries.XAxis = xAxis;
lineSeries.YAxis = yAxis;
lineSeries.Legend = legend;
ultraDataChart1.Axes.Add(xAxis);
ultraDataChart1.Axes.Add(yAxis);
ultraDataChart1.Series.Add(lineSeries);
}
1条答案
按热度按时间wqlqzqxt1#
要在图表中显示多条线,您需要在图表中添加多个
lineSeries
。在您的情况下,您可以按INST_ID
列对表中的数据进行分组,并为每个组创建一个lineSeries
。如下所示: