3

我对格式化 MS ASP.NET 图表控件的轴标签有疑问。在我深入探讨我的问题之前,请看一下这个截图。

在此处输入图像描述

正如您在屏幕截图中看到的那样,轴标签很难阅读并且看起来是粗体的。现在,我的问题是:

  • 哪些默认图表属性导致轴标签看起来不像 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
};

谢谢您的帮助。

4

1 回答 1

5

如果将图表的 BackColor 设置为Color.Transparent,则需要设置AntiAliasing="Graphics"

于 2011-12-21T09:36:40.230 回答