簡體   English   中英

不使用WinForms更改DataVisualization.Chart大小

[英]Changing DataVisualization.Chart size without using WinForms

我有一個Web服務,可以生成各種圖表。 這些圖表是使用System.Windows.Forms.DataVisualization.Charting以編程方式生成的,並將它們保存到.png文件中。 但是無論我做什么,圖表的尺寸都是300x300像素。

在Internet上,我發現了許多更改圖表大小的解決方案,但是它們僅適用於將圖表放入WinForm然后保存到文件的情況。

如果我的應用程序中沒有WinForms,如何更改圖表的大小?

這是我在代碼中所做的一個虛擬示例

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM