MSDN charts changing point values realtime?

独自空忆成欢 提交于 2019-11-30 22:33:52

Call chart1.Refresh() after changing the value; it will force a redraw of the chart, picking up the new values.

I've just found out that SetValueY() does not update the maximum interval in the Y axis. Therefore, if your current maximum is 0, it will not show anything higher than 0.

I do this:

    public static void Refresh(this Chart chart) // update changed data
    {
        chart.Series[0].Points.AddXY(1, 1);
        chart.Update();
        chart.Series[0].Points.RemoveAt(chart.Series[0].Points.Count-1);
    }

chart1.Refresh();

DataTable dtChartDataSource = Input from your side.

foreach (DataColumn dc in dtChartDataSource.Columns)
{
   //a series to the chart
 if (chart.Series.FindByName(dc.ColumnName) == null)
 {
      series = dc.ColumnName;
      chart.Series.Add(series);
      chart.Series[series].ChartType = SeriesChartType.Column;

    foreach (DataRow dr in dtChartDataSource.Rows)
    {
        double dataPoint = 0;
        double.TryParse(dr[dc.ColumnName].ToString(), out dataPoint);

        Yourchart.Series[seriesName].Points.AddXY("customStringsOnAxis", dataPoints);
    }
 }
}

It will add the x axis data and Y axis values to the Column chart.

Hope its helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!