我正在使用.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
答案 0 :(得分:2)
我遇到与MS Chart相同的问题,标签/图例文字总是以粗体显示,直到我添加TextAntiAliasingQuality属性:
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
答案 1 :(得分:1)
试试这个(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;
答案 2 :(得分:0)
我注意到AntiAliasing会影响字体。
尝试将其更改为AntiAliasing = AntiAliasingStyles.Graphics
。
答案 3 :(得分:0)
请将asp:chart TextAntiAliasingQuality的属性更改为“正常”
示例:
<asp:Chart ID="ActionChart" runat="server" Height="154px"
Width="282px" TextAntiAliasingQuality="Normal">
答案 4 :(得分:0)
对我有用的是在DataBind之后遍历序列点并在那里设置字体。
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;
}