MS图表控件:格式化轴标签
我对格式化MS ASP.NET图表控件的轴标签有疑问。在深入探讨我的问题之前,请看看这个截图。MS图表控件:格式化轴标签
正如你在截图中看到,轴标签是很难读,似乎加粗。现在,我的问题是:
- 哪些默认图表属性导致轴标签看起来不像Arial 11px常规,即粗体和紧密字符?
- 轴标签的外观如何更易于阅读和清理,即规则的字体重量和字符之间的分隔度?
该负责代码:
public Chart GetChart(ChartData chartDataData, IChartSettings settings)
{
var chart = new Chart
{
BackColor = Color.Transparent,
Height = settings.Height,
Palette = ChartColorPalette.None,
PaletteCustomColors = settings.PaletterCustomColors.ToArray(),
Width = settings.Width
};
if (settings.ShowLegend)
{
chart.Legends.Add("Legend").Alignment = StringAlignment.Center;
}
AddChartArea(chart);
foreach (var seriesData in chartDataData.Series)
{
AddSeries(chart, seriesData, settings.ChartType);
}
chart.AlignDataPointsByAxisLabel();
return chart;
}
private void AddChartArea(Chart chart)
{
var area = new ChartArea();
area.AxisX.LabelStyle.Angle = -45;
area.AxisX.MajorGrid.LineColor = Color.Transparent;
chart.ChartAreas.Add(area);
area.AxisX.LabelStyle.Font = area.AxisY.LabelStyle.Font = new Font("Arial", 11, GraphicsUnit.Pixel);
}
private void AddSeries(Chart chart, SeriesData data, SeriesChartType chartType)
{
var series = new Series
{
ChartType = chartType,
Name = data.Name,
ToolTip = data.Name,
Url = data.Url
};
foreach (var pointData in data.Points)
{
AddPoint(series, pointData.XValue, pointData.YValue);
}
chart.Series.Add(series);
}
private void AddPoint(Series series, string xValue, float yValue)
{
var point = new DataPoint
{
AxisLabel = xValue
};
point.SetValueXY(xValue, yValue);
series.Points.Add(point);
}
,其中用于设置代码对象是:
public static ChartSettings TaskSummary = new ChartSettings
{
ChartType = SeriesChartType.StackedColumn,
Height = Unit.Pixel(300),
Width = Unit.Pixel(450),
PaletterCustomColors = new[]
{
Color.FromArgb(191, 214, 151),
Color.FromArgb(249, 255, 149),
Color.FromArgb(191, 79, 75),
Color.Green
},
ShowLegend = true
};
感谢您的帮助。
如果将图表的BackColor设置为Color.Transparent
,则需要设置AntiAliasing="Graphics"
。
你可以参考文档,并解释它为什么工作? – KFL
我能找到的这个修复程序的最佳解释是在[here](https://social.msdn.microsoft.com/Forums/en-US/64c7d890-c98b-4392-9ec9-1b4af3e24300/labels-bold-when-背景透明?论坛= MSWinWebChart)。引用:“问题在于图表控件所使用的GDI +中”深“......当您使用透明背景在图像中绘制文本并且正在使用文本抗锯齿功能时,GDI +使用黑色作为默认背景来计算反锯齿效果,可以将纯色设置为背景,也可以使用Chart.AntiAliasing = AntiAliasingStyles.Graphics关闭文本消除锯齿;“ – KFL
你试过** area.AxisX.LabelStyle.Font.Bold = false **? 此外,玩字体大小,即将其更改为12,看看它是如何绘制然后... – woohoo