views:

225

answers:

1

How can i add labels for each and every yvalue in series of a rangebarchart ?

You all know that for plotting rangebartype series ,we need two yvalues as yvalue[0] and yvalue[1] .Here I need to add data labels to each of those yvalues( which means both at yvalue[0] and yvalue[1]).how can i implement that?can anybody suggest me?please!!

The label should look like as below for a rangebar(to be displayed on both sides of a rangebar).

Label1 ███████████████ Label2

                    Label███████████████████ Label
+1  A: 

There is no built-in way to do this in MS Chart. However, there is an ugly little workaround that will give you the display that you want.

For each datapoint (rangebar) that you want to display, you will need to create 2 datapoints that lie on top of one another. As an example:
DataPoint0: X=1 Y=5,10
DataPoint1: X=1 Y=10,5

These two datapoints lie right on top of one another, except one is displayed left-to-right and the other is displayed right-to-left.
For each DataPoint, under CustomProperties, there is the BarLabelStyle property. Set this to 'Outside' for both of the datapoints. Normally, this will display the label to the right of the range bar, but for DataPoint1, with the reversed Y values, the label is now placed to the left of the range bar. So, set your label for DataPoint0 to 10 (max value), and for DataPoint1 set the label to 5 (min value).

This will then look just like one range bar with the min value on the left and the max value on the right.

Caution: If either end of the range bar is too close to the edge of your graph, MS Chart, in its infinite wisdom, will force the label to be displayed inside the range bar. To overcome this, you can actually add a third number to the Y values of the DataPoint object. This third value is not displayed, but if it is larger than the largest Y value in your data series, it will force the chart to rescale to accommodate this larger value, so your labels are not forced inside the range bars. You could probably handle this another way with setting properties of the ChartArea also.

Stewbob
This is what i have done already.Anyhow thanks.Can't we draw a rectangle on both the sides of a range bar in which we can add some text? or Is there any way to draw a free text anywhere on MsChart?
Meera
There is no provision for drawing free text on the MS chart object. I keep running into all these little limitations in MS Chart. Even though it is basically a good custom control, in most cases I've chosen to use my own custom chart controls, because I can easily customize them for specialty tasks.
Stewbob
I have found the way to draw a free text on the MS chart using Graphics.DrawString method in the paint event of the chart.
Meera