2013-04-24 73 views
0

我在写一个GWT应用程序并使用highcharts。一些功能在Java中不可实现,但是在JavaScript中。我被给了一个如何实现我可以使用的东西的例子,但是我不知道如何包含在我的代码中。GWT Highcharts使用JSNI调用Javascript

我的代码包含变量声明为Chart graph;

我想这个答案Add tooltip to legend in highcharts when hovering

chart: { 
     type: 'column', 
     events: { 
      load: function() { 
       var chart = this, 
        legend = chart.legend; 

       for (var i = 0, len = legend.allItems.length; i < len; i++) { 
        var item = legend.allItems[i].legendItem; 
        item.on('mouseover', function (e) { 
         //show custom tooltip here 
         console.log("mouseover"); 
        }).on('mouseout', function (e) { 
         //hide tooltip 
         console.log("mouseout"); 
        }); 
       } 

      } 
     } 

    }, 

如何想补充一点能力,我的代码实现事件的节目。我试着用如下所示http://www.moxiegroup.com/moxieapps/gwt-highcharts/apidocs/index.html但我想不出一个办法做到这一点的chart.setOption(/图表/事件/负载”,对象o)。

我认为它会通过创建一个方法

完成
private native void foo(JavaScriptObject c)/*-{ 


}-*/; 

OR

private native void foo(Chart c)/*-{ 


}-*/; 

,但我不知道如何连接两个任何帮助表示赞赏

+0

你是什么意思由“使用高压图”?你是否使用moxiegroup的GWT包装版本?它只是作为一个JS资源被包含在内,并且你只是自己包装了必要的调用?是完全暴露在java中的项目中的高级API吗? – 2013-04-25 09:29:32

+0

是的,我使用moxiegroup的GWT包装版本。据我的理解是,highcharts API完全暴露在java中,但有一些内容我不想添加。 – bubbles 2013-04-25 17:56:56

回答

1

首先创建这样一个本地方法。!

private native void foo(JavaScriptObject chart)/*-{ 
    var legend = chart.legend; 

    for (var i = 0, len = legend.allItems.length; i < len; i++) { 
     var item = legend.allItems[i].legendItem; 

     item.on('mouseover', function (e) { 
      //show custom tooltip here 
      console.log("mouseover"); 
     }).on('mouseout', function (e) { 
      //hide tooltip 
      console.log("mouseout"); 
     }); 
    } 
}-*/; 

然后像这样调用这个方法连同setLoadEventHandler();

chart.setLoadEventHandler(new ChartLoadEventHandler() { 

     @Override 
     public boolean onLoad(ChartLoadEvent chartLoadEvent) { 
      foo(chart.getNativeChart()); 

      return true; 
     } 
    }); 

这就是全部!希望这会帮助你。