|
Data Labels not displayed |
Posted by Robert on Aug-23-2011 15:08 |
|
I am new to ChartDirector and struggling with what is likely a very simple problem.
I have a simple bar chart in which the data labels are not displaying.
My code is;
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim labels() As String = {"A", "B", "C"}
Dim data() As Double = {10, 20, 30}
Dim c As ChartDirector.XYChart = New ChartDirector.XYChart(720, 400)
c.setPlotArea(30, 10, 680, 350)
Dim layer As ChartDirector.BarLayer = c.addBarLayer
Dim colors() As Integer = {&HFFD700, &HFFFF00, &HB22222}
c.addBarLayer(data, colors)
Call layer.setDataLabelStyle("Arial Bold", 9)
Call layer.setDataLabelFormat("{value}")
Call layer.setDataLabelStyle.setAlignment(5)
' Set the labels on the x axis.
Call c.xAxis().setLabelStyle("Arialbold", 12)
Call c.xAxis().setLabels(labels)
' Output the chart
Me.WinChartViewerHC.Image = c.makeImage()
The resultant output displays the labels on the axis but no data labels are produced.
Any help would be greatly appreciated. |
Re: Data Labels not displayed |
Posted by Peter Kwan on Aug-24-2011 03:52 |
|
Hi Robert,
In your chart, there are two separate bar layers (your code calls addBarLayer twice). The "layer" variable refers to the first bar layer, which is empty, and therefore there is no label. The second bar layer does contain data, but your code have not configure any label for that bar layer.
For your case, instead of using:
Dim layer As ChartDirector.BarLayer = c.addBarLayer
..........
c.addBarLayer(data, colors)
please use:
Dim layer As ChartDirector.BarLayer = c.addBarLayer(data, colors)
The above adds only one bar layer, which has data, and sets the "layer" variable to refer to that bar layer.
Hope this can help.
Regards
Peter Kwan |
Re: Data Labels not displayed |
Posted by Robert on Aug-24-2011 12:55 |
|
Peter
Thank you very much for your rapid response. Much appreciated and now I understand both the problem and the solution, thanks to you.
Regards,
Robert |
|