Monday, May 07, 2012 4:31 PM
A problem with my chart;
With code below, a chart is generated with on "rowindex 0", the x value of the origin by default.
On "rowindex 1", there are customlabels at certain intervals. At the origin, there is also a customlabel, just below the other one.
In the end, I want to put all the labels on index 0. But if I do that, both the customlabel and the default label at the origin disappear. Which is very annoying. According to the link below, all labels from the axis disappear if you add custom labels at row 0. But also the customlabel at the origin disappears. Is there a solution for this?
Chart1.ChartAreas.Clear() Chart1.Series.Clear() Chart1.ChartAreas.Add("ChartArea1") Chart1.ChartAreas(0).AxisX.Minimum = Xmin Chart1.ChartAreas(0).AxisY.Minimum = Ymin Chart1.ChartAreas(0).AxisX.Maximum = Xmax Chart1.ChartAreas(0).AxisY.Maximum = Ymax Chart1.ChartAreas(0).AxisX.IntervalAutoMode = False Chart1.ChartAreas(0).AxisY.IntervalAutoMode = False Chart1.ChartAreas(0).AxisX.IsLogarithmic = True Chart1.ChartAreas(0).AxisY.IsLogarithmic = True Chart1.ChartAreas(0).AxisX.Title = "Xtitle" Chart1.ChartAreas(0).AxisY.Title = "Ytitle" Dim stap As Double = 0.5 For x = Chart1.ChartAreas(0).AxisX.Minimum To Chart1.ChartAreas(0).AxisX.Maximum Step stap Chart1.ChartAreas("ChartArea1").AxisX.CustomLabels.Add(Math.Log10(x - 0.1), Math.Log10(x + 0.1), CStr(x), 1, LabelMarkStyle.None, GridTickTypes.All) Next 'for Y customlabels is identical
this link; http://msdn.microsoft.com/en-us/library/dd456628.aspx
Wednesday, May 09, 2012 2:07 PM
Finally found the answer;
I don't know if this is the easiest way, but at least it works to get all custom labels on rowindex 0 (to change the labelstyle) and keep the label at the origin of the chart visible.
1) generate all customlabels on rowindex 1, except on the origin and also keep the setting "IsEndLabelVisible = true"
2) during prepaint, change customlabels.rowindex to 0
Chart1.ChartAreas(0).AxisX.LabelStyle.IsEndLabelVisible = True For x = Minimum + stap To Maximum Step stap Chart1.ChartAreas("ChartArea1").AxisX.CustomLabels.Add(Math.Log10(x - 0.2), Math.Log10(x + 0.2), CStr(x), 1, LabelMarkStyle.None, GridTickTypes.All) Next For Each label In Chart1.ChartAreas(0).AxisX.CustomLabels label.RowIndex = 0 label.Axis.LabelStyle.Angle = 0 Next
An extra difficulty I encountered is when the label of a point is near a label on the axis; the label on the axis disappears then.
- Marked As Answer by MTHulli Wednesday, May 09, 2012 2:07 PM