【问题标题】:Add Multiple series to a chart dynamically in asp.net在asp.net中动态地将多个系列添加到图表中
【发布时间】:2012-10-22 11:55:41
【问题描述】:

我想在图表中添加动态系列。

我有一个数据,比如日期,总计。我想在图表上绘制这些点。

我从sql数据库中获取数据并绑定。

我想绘制动态更新的数据表中的数据。

Series newSeries=new Series();
newseries.ChartType=SeriesChartType.Line;
newSeries.BorderWidth = 3;
Chart1.Series.Add(newSeries);
newSeries.XValueMember = "date1";
newSeries.YValueMembers = "total";
Chart1.DataBind();

这是在树视图的最后一系列中绘制的。 请帮我解决这个问题?

【问题讨论】:

  • 你可以试试asp.net图表控件archive.msdn.microsoft.com/mschart
  • 我已经在使用 asp.net 图表控件了。在将数据添加到系列时,我无法从数据表中绑定动态数据,我想添加具有在循环中调用的相同数据表的动态系列。所以它总是更新数据。

标签: asp.net c#-4.0


【解决方案1】:
 foreach(DataRow row in myDataSet.Tables["Query"].Rows)
    {
        // For each Row add a new series
        string seriesName = row["SalesRep"].ToString();
        Chart1.Series.Add(seriesName);
        Chart1.Series[seriesName].ChartType = SeriesChartType.Line;
        Chart1.Series[seriesName].BorderWidth = 2;

        for(int colIndex = 1; colIndex < myDataSet.Tables["Query"].Columns.Count; colIndex++)
        {
            // For each column (column 1 and onward) add the value as a point
            string columnName = myDataSet.Tables["Query"].Columns[colIndex].ColumnName;
            int YVal = (int) row[columnName];

            Chart1.Series[seriesName].Points.AddXY(columnName, YVal);
        }
    }

【讨论】:

  • 谢谢,如果此解决方案对您有用,请不要忘记点击答案
  • 这里我的图表绘制工作正常。但在图表的末尾网格线不清楚
  • 我认为可能是间隔问题,您可以使用以下选项 Chart1.ChartAreas["Area1"].AxisX.MajorGrid.Enabled chtMain.ChartAreas["Area1"].AxisX.Interval = 120 也如果可能附上图片,所以更好地了解问题
  • 这段代码工作正常,但我想显示图例及其显示两次,因为我有两个系列。怎么可能所有系列都显示一次传奇??
猜你喜欢
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 2014-12-20
  • 2021-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-05
相关资源
最近更新 更多