2013-01-02 49 views
1

我在MySQL和一些查詢後的結果一些銷售數據增添更多的價值會是這樣的:在圖表中的VS 2010

year |sales | 
2008 |100000 | 
2009 |120040 | 
2010 |239000 | 
2011 |300900 | 
2012 |200900 | 

這些數據會在圖表上顯示,現在我想從明年的一些數據預測增加一個值,並將其顯示在圖表上

我試過這段代碼:

myChart.Series[0].Points[0].XValue = (year + 1); 
    myChart.Series[0].Points[0].YValues = dataForecasting; 

,但沒有發生,我怎麼能在圖表上添加一個值?我想連續線圖,所以從2008年到2013年,只有一個系列

回答

1
chart1.Series.Clear(); 

    List<string> years = new List<string> { "1994", "1995", "1996", "1997" }; 
    List<double> yearSales = new List<double> { 10000.23, 98000, 95876, 78097 }; 


    Series yearSeries = chart1.Series.Add("sales"); 
    yearSeries.Points.DataBindXY(years, yearSales); 
    yearSeries.ChartType = SeriesChartType.Line; 

    // do stuff.... 

    // add one more value 

    years.Add("1998"); 
    yearSales.Add(12345.67); 
    yearSeries.Points.DataBindXY(years, yearSales); 
+0

,但我希望有一個連續的線圖,所以從2008年到2013年,只有一個系列,一個線,但你的代碼將增加另一個數據系列 – Darjeeling

+1

將數值保存在數組中,如示例中所示。如果要在同一系列中使用新數據點更新圖表,請將該值添加到現有數組中,並重新調用「thisYear.Points.DataBindXY」,它將使用數組更新圖表,該數組將包含額外的值。 .. –

+0

我修改了我的示例 –