2013-12-16 91 views
2

我想使用gwt-highchart(使用最新的gwt-highchart 1.6.0和Highstock 2.3.4版本)添加系列到我的图表应用程序。一切似乎都很好,直到第三个系列。当我尝试添加第三个我得到这个错误:HighCharts股票图表错误代码18

com.google.gwt.core.client.JavaScriptException: (String) 
@org.moxieapps.gwt.highcharts.client.BaseChart::nativeAddSeries(Lcom/google/gwt/core 
/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;ZZ)([JavaScript 
object(4953), JavaScript object(5135), bool: true, bool: true]): Highcharts error #18: 
www.highcharts.com/errors/18 

这里是我的代码(内循环运行):

  // Create a new serie with a new yAxis 
     Series newSeries = chart.createSeries().setYAxis(index).setPlotOptions(new LinePlotOptions().setColor(tag.getColor())); 

     // Set new yAxis options 
     chart.getYAxis(index).setPlotLines(chart.getYAxis(index).createPlotLine().setValue(0).setWidth(1).setColor(tag.getColor())).setLabels(new YAxisLabels().setEnabled(false)).setTickLength(0).setOffset(60).setStartOnTick(false) 
       .setEndOnTick(false).setGridLineWidth(0).setMaxPadding(DEFAULT_YAXIS_MAX_PADDING).setMinPadding(DEFAULT_YAXIS_MIN_PADDING) 
       .setAxisTitle(new AxisTitle().setText(null).setStyle(new Style().setColor(tag.getColor()))); 

     // Add the serie to the chart 
     chart.addSeries(newSeries.setName("Test " + index)); 

前两个系列都OK,因为我之前,但三分之一的人说一个抛出上面的异常(当我调试应用程序时,我可以看到新创建的yAxis引用)。

这里是会抛出异常的行:

chart.addSeries(newSeries.setName("Test " + index)); 

感谢

+0

如果您不添加第3个系列,您是否得到图表? Highcharts错误#18:请求的轴不存在。你在同一行中调用两次'.setPlotLines()'。一旦选择了,另一次没有。这可以吗? –

+0

感谢@AntoJurković为你的超级快速评论:)如果我不添加第3个系列,它几乎没有问题(但有时我会看到范围选择栏中的第二个系列!)顺便说一句,我删除了无参数调用'.setPlotLines()'但没有任何改变。 – ngc4151

回答

2

我已经理解了它终于来了!

GWT-HighCharts似乎是问题所在。它根本不会将新的YAxis添加到图表中。所以你必须通过像这样的本地调用来添加YAxis;

private static native void nativeAddAxis(JavaScriptObject chart, JavaScriptObject axisOptions, boolean isX, boolean redraw, boolean animationFlag) /*-{ 
    chart.addAxis(axisOptions, isX, redraw, animationFlag); 
}-*/; 

在添加新系列之前,请调用此本机方法。

  // Create new series 
     Series newSeries = chart.createSeries().setYAxis(index); 
     newSeries.setPlotOptions(new LinePlotOptions().setColor(tag.getColor())); 
     newSeries.setName(index + 1 + ") "); 

     // Create a new YAxis 
     YAxis yAxis = chart.getYAxis(index).setPlotLines(chart.getYAxis(index).createPlotLine().setValue(0).setWidth(1).setColor(tag.getColor())).setLabels(new YAxisLabels().setEnabled(false)).setTickLength(0).setOffset(60) 
       .setStartOnTick(false).setEndOnTick(false).setGridLineWidth(0).setPlotLines().setMaxPadding(DEFAULT_YAXIS_MAX_PADDING).setMinPadding(DEFAULT_YAXIS_MIN_PADDING) 
       .setAxisTitle(new AxisTitle().setText(null).setStyle(new Style().setColor(tag.getColor()))); 

     // IMPORTANT!: New YAxis must be added to the chart via native calls since gwt-highcharts wrapper doesn't do that properly! 
     nativeAddAxis(chart.getNativeChart(), yAxis.getOptions().getJavaScriptObject(), false, false, false); 

     // Physical attach 
     chart.addSeries(newSeries); 
1

请检查索引值。 如果索引大于轴计数,则可能发生此错误

highcharts错误#18指示尝试访问的轴不存在。

这里是链接http://www.highcharts.com/errors/18

希望这将有助于你

+0

我检查了索引值,没有错。实际上,当我调试应用程序时,我可以在图表实例中看到新创建的YAxises,但是当我尝试添加该系列时,找不到关联的轴(但它在那里,我可以在调试模式下看到它) – ngc4151

2

以下是此类错误的原因:

如果使用GWT-HighCharts包装,必须在添加图表,DOM之前进行配置!看起来,将它添加到DOM后,任何配置更改似乎都不起作用!

快乐编码!