Menu

Is it possible to get the renderer if the chart?

2012-07-05
2012-07-25
  • Nabeel Mukhtar

    Nabeel Mukhtar - 2012-07-05

    In highcharts you can get the renderer (http://www.highcharts.com/ref/#renderer) of the chart and then display images or text on it. e.g.
    http://jsfiddle.net/senyahnoj/NfStH/1/

    Is it possible to do it in GWT Highcharts?

    Thanks for your help.

    Regards
    Nabeel Mukhtar

     
  • Shawn Quinn

    Shawn Quinn - 2012-07-05

    You can grab the native Highcharts JS instance via the GWT Highcharts "Chart.getNativeChart()" instance, and then from there you can use JSNI to operate against the native properties of the object as needed. Note that if you want to utilize the native instance before the chart is rendered you'll need to use deferred scheduling of the logic. Here's a working example:

    private Chart chartRendererTest() {
        final Chart chart = new Chart()
            .setType(Series.Type.SPLINE)
            .setChartTitleText("Lawn Tunnels");
        Series series = chart.createSeries()
            .setName("Moles per Yard")
            .setPoints(new Number[]{163, 203, 276, 408, 547, 729, 628});
        chart.addSeries(series);
        Scheduler.get().scheduleDeferred(new Command() {
            public void execute() {
                renderText(chart.getNativeChart(), "Hello there", 10, 10);
            }
        });
        return chart;
    }
    
    private static native JavaScriptObject renderText(JavaScriptObject chart, String text, int plotX, int plotY) /*-{
        return chart.renderer.text(text, plotX, plotY).add();
    }-*/;
    

    Let us know if that meets your needs, or if you're looking for something different.

     

    Last edit: Shawn Quinn 2012-07-05
    • Andrew_X

      Andrew_X - 2012-07-17

      Hello, thanks for this advice, but if I try exporting chart as image I don't see the pictures I added with help of
      chart.renderer.image()
      Is there any possibility to export chart with images you added?

       
      • Shawn Quinn

        Shawn Quinn - 2012-07-17

        I'm not quite sure if there's anyway to get Highcharts to add additional content to the SVG routine that is posted to the Batik converter on export, but your best bet would be checking on the main Highcharts forums as someone there will likely know better.

         
        • Andrew_X

          Andrew_X - 2012-07-18

          Here is my post on Highcharts forum. There is an answer with code written on JavaScript.
          How can I do the same with GWT Highcharts?

          Thanks!

           
          • Andrew_X

            Andrew_X - 2012-07-19

            Any ideas about how to do this?

             
            • Shawn Quinn

              Shawn Quinn - 2012-07-25

              Seems like you can mimic that JS using similar code as noted above in this thread to grab the native renderer and add the image information. Note that GWT Highcharts also supports a ChartLoadEventHandler (which utilizes the Highcharts "load" event) if you need it. In this case, the "scheduleDeferred" approach used above may be easier to use to access the native chart instance. I haven't tried to add custom details the renderer before on my own though, so if you run into trouble - just let us know.

               
  • Nabeel Mukhtar

    Nabeel Mukhtar - 2012-07-06

    Thanks a lot. That's exactly what I needed.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.