我正在生成System.Web.UI.DataVisualization.Charting
图表,以便将它们动态插入到.docx
文档中。
问题是它们的宽度取决于图形和轴标签长度的大小,因此具有较长标签的图形最终在输出文档上显得较小。
我使用的方法将标签拼接到不同的行上,但这似乎不会影响图表的大小。
以下是我的图表生成方法之一:
private static MemoryStream CreateRadarChartImage(IEnumerable<SectionDs> sections)
{
var chart = new Chart { BackColor = Color.Transparent, Width = 550, Height = 350 };
var series = new Series("Series")
{
ChartArea = "chartArea",
ChartType = SeriesChartType.Radar,
BorderWidth = 1,
BorderColor = Color.Black,
BorderDashStyle = ChartDashStyle.Solid,
Color = Color.Transparent
};
foreach (SectionDs section in sections)
{
var labelText = SpliceText(section.Name, 14);
series.Points.Add(
new DataPoint { AxisLabel = labelText, LabelAngle = 40, YValues = new[] { section.OverallScore * 100 } });
}
chart.Series.Add(series);
var chartArea = new ChartArea("chartArea") { BackColor = Color.Transparent, AxisY = { Maximum = 100 }, AxisX = { LabelStyle = { Font = new Font("Calibri", 15f) } } };
chart.ChartAreas.Add(chartArea);
var chartImage = new MemoryStream();
chart.SaveImage(chartImage, ChartImageFormat.Png);
return chartImage;
}
答案 0 :(得分:0)
var chartArea = new ChartArea("chartArea") { BackColor = Color.Transparent, AxisY = { Maximum = 100 }, AxisX = { LabelStyle = { Font = new Font("Calibri", 15f) } } };
chartArea.AxisX.IsLabelAutoFit = false;
chart.ChartAreas.Add(chartArea);
这将停止标签的自动装配,因此每个图表将具有相同尺寸的标签。您现在可能需要对标签进行一些手动格式化