本文介绍了ChartControl的SaveImage无屏幕显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想救一个ChartControl到图像,而不在屏幕上显示它

I wanna save a ChartControl to an Image without display it in the screen.

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);



然后,我得到了一个空白的画面。我想这是因为该控件不画。这可能吗?

Then I get a blank picture. I think it's because the control is not paint. Is it possible ?

推荐答案

下面的遗漏部分答案

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);

这篇关于ChartControl的SaveImage无屏幕显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 18:38