Reputation: 1270
I am creating a chart-graphic with the .net char controls. My problem is that the value-labels and the axis-labels are always bold if i dont use a white or transparent background!
.ChartAreas(0).AxisY.LabelStyle.Font = New Drawing.Font("Arial", 8.0F, FontStyle.Regular)
i set the font as regular, but it only appears as regular on my white background. i am alternating backgrounds from white to gray. the font on the gray is always bold.
Any suggestions?
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
Upvotes: 1
Views: 6416
Reputation: 49
What worked for me was looping through the Series Points after DataBind and setting the font there.
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;
}
Upvotes: 0
Reputation: 56
I had the same issue with MS Chart, the label/legend text is always bold until I add the TextAntiAliasingQuality attribute:
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
Upvotes: 2
Reputation: 1
Pleasechange property of asp:chart TextAntiAliasingQuality to "Normal"
example:
<asp:Chart ID="ActionChart" runat="server" Height="154px"
Width="282px" TextAntiAliasingQuality="Normal">
Upvotes: 0
Reputation: 604
I noticed that AntiAliasing can affect fonts.
Try changing it to AntiAliasing = AntiAliasingStyles.Graphics
.
Upvotes: 0
Reputation: 1406
Try this (where ChartAreas["A"] = your 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());
Also try changing your font to a font that has both a Regular and Bold appearance
For instance:
System.Drawing.Font f = new System.Drawing.Font("Tahoma", 10, FontStyle.Regular);
chart1.ChartAreas["A"].AxisY.LabelStyle.Font = f;
Upvotes: 3