ChartControl的SaveImage没有显示它在屏幕上

时间:2015-04-30 10:44:33

标签: c# image controls microsoft-chart-controls

我想将ChartControl保存到图像而不在屏幕上显示它。

var theChart = new Chart();
var theSeries = new Series("values");
theSeries.IsVisibleInLegend = false;
theChart.Series.Add(theSeries);
theSeries.Points.AddXY(1, 1);
theSeries.Points.AddXY(2, 2);
theSeries.Points.AddXY(3, 3);
theChart.SaveImage(@"D:\Téléchargements\HiddenChart4.png", ChartImageFormat.Png);

然后我得到一张空白照片。我认为这是因为控制不是油漆。有可能吗?

1 个答案:

答案 0 :(得分:3)

这里是缺少部分的答案

var theChart = new Chart();

        //missing part
        var chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
        theChart.ChartAreas.Add(chartArea1);

        var theSeries = new Series("values");
        theSeries.IsVisibleInLegend = false;
        theChart.Series.Add(theSeries);
        theSeries.Points.AddXY(1, 1);
        theSeries.Points.AddXY(2, 2);
        theSeries.Points.AddXY(3, 3);
        theChart.SaveImage(@"D:\Téléchargements\HiddenChart6.png", ChartImageFormat.Png);