[英]Changing DataVisualization.Chart size without using WinForms
I have an Web Service that generates different kinds of charts. 我有一个Web服务,可以生成各种图表。 The charts are generated programatically using
System.Windows.Forms.DataVisualization.Charting
and they are saved to .png files. 这些图表是使用
System.Windows.Forms.DataVisualization.Charting
以编程方式生成的,并将它们保存到.png文件中。 But whatever I do, the charts have the dimension 300x300 pixels. 但是无论我做什么,图表的尺寸都是300x300像素。
On the internet I have found many solutions on changing the size of the chart, but they only apply to situations where the chart is put into a WinForm and then saved to a file. 在Internet上,我发现了许多更改图表大小的解决方案,但是它们仅适用于将图表放入WinForm然后保存到文件的情况。
How can I change the size of the chart if I don't have WinForms in my application? 如果我的应用程序中没有WinForms,如何更改图表的大小?
This is a dummy example of what I do in my code 这是我在代码中所做的一个虚拟示例
int[] yVal = { 1, 1, 1, 1, 1, 1, 1 };
string[] xName = { "a", "b", "b", "b", "b", "b", "b" };
System.Windows.Forms.DataVisualization.Charting.Chart Chart1 = new Chart();
Chart1.Titles.Add("Title");
Chart1.Series.Add(new Series());
Chart1.Series[0].XValueType = ChartValueType.String;
Chart1.Series[0].YValueType = ChartValueType.Int32;
Chart1.Series[0].Points.DataBindXY(xName, yVal);
Chart1.Palette = ChartColorPalette.EarthTones;
Chart1.Legends.Add(new Legend());
Chart1.Legends[0].Enabled = false;
ChartArea chartArea = new ChartArea();
chartArea.AxisX.Title = "X";
chartArea.AxisY.Title = "Y";
Chart1.ChartAreas.Add(chartArea);
Chart1.SaveImage("chart.png", ChartImageFormat.Png);
要获得1000px x 1000px的大图像,请在图表初始化后添加以下行:
Chart1.Size = new Size(1000, 1000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.