1

我正在使用 .net char 控件创建图表图形。我的问题是,如果我不使用白色或透明背景,值标签和轴标签总是粗体!

.ChartAreas(0).AxisY.LabelStyle.Font = New Drawing.Font("Arial", 8.0F, FontStyle.Regular)

我将字体设置为常规字体,但它仅在我的白色背景上显示为常规字体。我正在从白色到灰色交替背景。灰色的字体总是粗体。

有什么建议么?

Dim myChart As New Chart
        With myChart
            .Width = 685 + 130
            .Height = 45 + letzteZusatz * 2
            .RenderType = RenderType.ImageTag
            .AntiAliasing = AntiAliasingStyles.All
            .TextAntiAliasingQuality = TextAntiAliasingQuality.High
            If white Then
                .BackColor = Color.FromArgb(100, 252, 252, 252)
                white = False
            Else
                .BackColor = Color.FromArgb(100, 220, 220, 220)
                white = True
            End If
            .ChartAreas.Add("ChartArea1")
            .ChartAreas("ChartArea1").Area3DStyle.Enable3D = False
            With .ChartAreas(0)
                .BackColor = Color.Transparent
                .BorderWidth = 0
                .AxisX.LineWidth = 0
                .AxisY.LineWidth = CType((0 + (letzteZusatz * 0.1)), Integer)
                .AxisY.LineColor = Color.FromArgb(100, 194, 195, 192)
                .AxisY.Minimum = minimum
                .AxisY.Maximum = CType(maximum * 1.1, Integer)
                .AxisX.LabelStyle.Enabled = False
                .AxisY.LabelStyle.Enabled = True
                .AxisY.LabelStyle.Angle = 0
                .AxisY.LabelStyle.Format = "N0"
                .AxisY.LabelStyle.Font = New Drawing.Font("Arial", 8.0F, FontStyle.Regular)
                .AxisY.IsLabelAutoFit = False
                .AxisY.LabelAutoFitStyle = LabelAutoFitStyles.None
                .AxisX.MajorGrid.Enabled = False
                .AxisY.MajorGrid.Enabled = True
                .IsSameFontSizeForAllAxes = True
                .AxisY.MajorGrid.LineColor = Color.FromArgb(100, 194, 195, 192)
                .AxisY.MajorTickMark.Enabled = True
                .AxisY.MinorTickMark.Enabled = False
                .AxisX.MajorTickMark.Enabled = False
                .AxisX.MinorTickMark.Enabled = False
                .AxisY.MajorTickMark.LineColor = Color.FromArgb(100, 194, 195, 192)
                .BorderWidth = 0
                .AlignmentOrientation = AreaAlignmentOrientations.Vertical
                .InnerPlotPosition = New ElementPosition(16, 0, 84, CType((100 - (letzteZusatz * 3)), Single))
            End With

            .DataBindTable(BuildChartTabel(o, seite), "Name")
For Each s As Series In myChart.Series
            s.ChartType = SeriesChartType.Bar
            s.BorderWidth = 0
            s.MarkerSize = 0
            s.IsValueShownAsLabel = True
            s("PixelPointWidth") = "45"
            For Each p As DataPoint In s.Points
                p.BackImage = "~/img/bg_chart.png"
                p.BackImageWrapMode = ChartImageWrapMode.Tile
                p.BorderWidth = 0
                p.MarkerSize = 0
            Next
        Next
    End With

    Using chartimage = New FileStream("D:\test.png", FileMode.Create)
        myChart.SaveImage(chartimage, ChartImageFormat.Png)
        chartimage.Flush()
    End Using
4

5 回答 5

3

试试这个(其中 ChartAreas["A"] = 你的 ChartAreas(0)):

chart1.ChartAreas["A"].BackColor = Color.Gray;
chart1.BackColor = Color.Gray;
//
chart1.ChartAreas["A"].AxisY.LabelStyle.Font = new System.Drawing.Font(chart1.ChartAreas["A"].AxisY.LabelStyle.Font,
                                                                       FontStyle.Regular);
MessageBox.Show(chart1.ChartAreas["A"].AxisY.LabelStyle.Font.Bold.ToString());

还可以尝试将字体更改为同时具有常规和粗体外观的字体

例如:

System.Drawing.Font f = new System.Drawing.Font("Tahoma", 10, FontStyle.Regular);
chart1.ChartAreas["A"].AxisY.LabelStyle.Font = f;
于 2013-07-26T08:52:08.727 回答
2

我对 MS Chart 有同样的问题,标签/图例文本总是粗体,直到我添加 TextAntiAliasingQuality 属性:

chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;

于 2014-06-07T06:29:51.883 回答
0

我注意到抗锯齿会影响字体。

尝试将其更改为AntiAliasing = AntiAliasingStyles.Graphics.

于 2013-11-29T15:22:10.100 回答
0

请将 asp:chart TextAntiAliasingQuality 的属性更改为“Normal”

例子:

<asp:Chart ID="ActionChart" runat="server" Height="154px" 
                Width="282px" TextAntiAliasingQuality="Normal">
于 2013-12-07T07:12:16.277 回答
0

对我有用的是在 DataBind 之后循环遍历 Series Points 并在那里设置字体。

        Chart.DataBind();

        System.Drawing.Font f = new System.Drawing.Font("Helvetica", 15, FontStyle.Regular);

        foreach (var dp in Chart.Series["PieChartSeries"].Points)
        {
            dp.Font = f;
        }
于 2020-04-14T18:11:23.797 回答