PlotLine Labels

Mar 27, 2012 at 6:04 AM

I'm trying to add a label to a PlotLine, the line shows up, but no label. Here is what I have so far, not sure I am on the right track with the formatter. A C# or VB example would help a lot.

Dim pLine As New PlotLine           

pLine.value = 1500            

pLine.label = New Labels()           

pLine.label.formatter = "text"

pLine.label.align = Align.left           

pLine.width = 2           

pLine.color = "blue"

Developer
Mar 30, 2012 at 4:21 PM

Hi MxBlinkPx,

You were on the right path. Unfortunately, there was an omission on our part from the Labels class. It appears that to set the label's text, it needs to have the property 'text' of type string. This is something that is not mentioned in the API documentation for Highcharts, but is used in an example for Highstocks (that is where I picked it up from).

Ideally, you should inherit a new PlotLabel class from Labels and add the 'text' property to the new class. Then use this class in PlotLine and PlotBand classes (instead of using Labels). This is because the Labels class is also used by Axis, and the 'text' property is not required for that one. But if you have the code itself, you can also add the 'text' property directly to the class itself for a quick fix to your problem.

This bug will also be fixed in a the next changeset.

Please let us know if the changes work for you.

Regards,

Rahul

Mar 30, 2012 at 5:23 PM

Rahul,

Thanks, I did wind up figuring that out. The other thing I noticed if you are interested:

I had to add "public string stack;" to the Serie class to allow stacking in different groups for columns. (http://www.highcharts.com/demo/column-stacked-and-grouped

Other than that, I think everything else I tried was working. The formatter was a little tricky to figure out, how to supply a function. Maybe post an example in a sample if you haven't?

Developer
Mar 30, 2012 at 8:24 PM

You make a good point. And I'm thinking about adding the 'stacking' property to Serie, but I'm not sure it should be there since 'stacking' is not valid for all serie types, but the Serie class is common for all chart types.

But then, in the worst case, the parameter will simply be ignored if it does not apply. So i guess no real damage done either.. What do you think about it?

Mar 30, 2012 at 8:58 PM

It's probably fine to just add it to the Serie class. I primarily work with Google Web Toolkit(GWT) and there was recently a great adapter to use Highcharts with it, much like this one for .NET. For example, here is the Series class from that, and it appears they allow stacking in the generic Series:

http://www.moxiegroup.com/moxieapps/gwt-highcharts/apidocs/org/moxieapps/gwt/highcharts/client/Series.html

The homepage:

http://www.moxiegroup.com/moxieapps/gwt-highcharts/

That is one of the best adapters I've used, so if you are unsure of how to structure something, it might be worth consulting the javadocs and seeing how they did it.