2

我有一个 ASP.NET MVC 应用程序。此应用程序需要在运行时创建一个圆环图并将图像保存到文件系统。圆环图必须包含将在运行时生成和添加的文本注释。目前,我可以成功创建一个圆环图。但是,文本注释永远不会出现。此外,不会抛出任何错误。对于我的生活,我无法弄清楚我做错了什么。这是我正在尝试的:

string[] xValues = { "1", "2" };
double[] yValues = { 30, 70 };

// Create a donut chart
Chart chart = new Chart();
chart.Width = 360;
chart.Height = 240;

// Setup the custom color palette
chart.Palette = ChartColorPalette.None;
chart.PaletteCustomColors = GetPaletteColors();

// Build a donut series
Series series = new Series("Default");
series.ChartType = SeriesChartType.Doughnut;
chart.Series.Add(series);

// Define the chart area
ChartArea chartArea = new ChartArea();
chartArea.Position = new ElementPosition(0, 1.9f, 59.5f, 100);
chart.ChartAreas.Add(chartArea);

// Create the axes as necessary
Axis yAxis = new Axis(chartArea, AxisName.Y);
Axis xAxis = new Axis(chartArea, AxisName.X);

// Bind the data to the chart
chart.Series["Default"].Points.DataBindXY(xValues, yValues);

// Add the text information
TextAnnotation annotation = new TextAnnotation();
annotation.Text = GetText();
annotation.Font = new Font(new FontFamily("Verdana"), 10.5f);
annotation.ForeColor = Color.FromArgb(255, 45, 45, 45);
annotation.X = 10;
annotation.Y = 10;
annotation.BringToFront();
chart.Annotations.Add(annotation);

chart.SaveImage("chart.png", ChartImageFormat.Png);

为什么圆环图上没有出现 TextAnnotation?非常感谢您的帮助。我已经为此苦恼了一天。

4

0 回答 0