I have a chart in Highcharts (to be more specific: it's a Highstocks chart, candlesticks type) and now I want to add some SVG shapes to it.
I know there is this renderer object, but it only accepts x- and y-coordinates relative to the canvas.
What I need is to add some shapes at a specific TIME (xAxis), so I either need it to accept x/y vales as the chart coordinates (not the canvas coordinates) (which I clearly doubt is possible) or we need to get the x/y-canvas-position of a specific point inside the chart.
Is there any way to do this?
You can extend existing symbols via
$.extend(Highcharts.Renderer.prototype.symbols, {
newSymbol: function() {
return [//SVG path as Array];
}
});
Here is a fiddle demonstrating that
To draw SVG shape and move it with the zoom , there is two ways i used the first one just take it as an idea and see if you can do it better than me , second way always works
the first way
Get the x coordinate for this shape : as you know highstock use unix time , so lets say you want to add your shape at X data = 1326844540000 , now get the x position for 1326844540000 according to series[i] i will assume that you have one series so use series[0] , here is how you get the x-coor :
$.each(chart.series[0].points, function(index,value){
if(value.category == 1326847170000 )
console.log(this.plotX) ;
});
now use .append() to add your SVG :
var myrect = $(".highcharts-series-group") ;
$(myrect).append(<your svg goes here with
x ="you have it from the previous code " y="")
this code will go inside (xAxis - events - setExtremes ) And o nchart load as well
the recommended way
the recommended and guranteed way is to create a flag give it an id and then you can do what ever you want by editing the attr() of this flag
UPDATE

<g> tag is what you will edit to draw what ever you want If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With