I need to find the pixel location of a point to place a LabelItem on the graph. I see that in the Javascript there is a chart.getXAxis().translate(pt) but it is not part of the GWT api. Can you add it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As a workaround I tried:
private native int getXPixel(JavaScriptObject chart,int pt) /-{
try {
return chart.plotLeft+chart.xAxis[0].translate(pt);
} catch(e) {
alert(e.message);
}
}-/;
and called getXPixel(chart.getNativeChart(),pt);
The problem is that I am trying to position a LabelItem based a point location. The above only works after the chart is rendered but the LabelItems don't appear if I call chart.setLabelItems after chart is rendered. What am I missing?
Also the above returns a number like 173.13455 when I expected an integer.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Indeed, I can confirm that LabelItems added after rendering are not displayed, even after a chart.redraw().
I think we can have a reasonable simulation of them with a function I found somewhere, using chart.renderer.text().
Funnily, I can't find translate() in the Highcharts reference, but I found a forum post (with jsFiddle example) using it, and indeed it is in the sources.
After some experimentations (new to JSNI stuff), I came up with a reasonable workaround.
I need to find the pixel location of a point to place a LabelItem on the graph. I see that in the Javascript there is a chart.getXAxis().translate(pt) but it is not part of the GWT api. Can you add it?
As a workaround I tried:
private native int getXPixel(JavaScriptObject chart,int pt) /-{
try {
return chart.plotLeft+chart.xAxis[0].translate(pt);
} catch(e) {
alert(e.message);
}
}-/;
and called getXPixel(chart.getNativeChart(),pt);
The problem is that I am trying to position a LabelItem based a point location. The above only works after the chart is rendered but the LabelItems don't appear if I call chart.setLabelItems after chart is rendered. What am I missing?
Also the above returns a number like 173.13455 when I expected an integer.
Indeed, I can confirm that LabelItems added after rendering are not displayed, even after a chart.redraw().
I think we can have a reasonable simulation of them with a function I found somewhere, using chart.renderer.text().
Funnily, I can't find translate() in the Highcharts reference, but I found a forum post (with jsFiddle example) using it, and indeed it is in the sources.
After some experimentations (new to JSNI stuff), I came up with a reasonable workaround.
and in onClick() of chart.setClickEventHandler()'s anonymous class, I do:
You might want to add some offset to posX and posY to put them farther of the marker.
Note: at first, I tried int as return value, but the DevMode of GWT warned that it had to convert the Double return value to int...