Gwt HighCharts股票图表错误代码18
我正在尝试使用gwt highchart(使用最新的gwt highchart 1.6.0和Highstock 2.3.4版本)将系列添加到图表应用程序中。在第三季之前,一切似乎都很好。当我尝试添加第三个时,出现以下错误:Gwt HighCharts股票图表错误代码18,gwt,highcharts,highstock,gwt-highcharts,Gwt,Highcharts,Highstock,Gwt Highcharts,我正在尝试使用gwt highchart(使用最新的gwt highchart 1.6.0和Highstock 2.3.4版本)将系列添加到图表应用程序中。在第三季之前,一切似乎都很好。当我尝试添加第三个时,出现以下错误: com.google.gwt.core.client.JavaScriptException: (String) @org.moxieapps.gwt.highcharts.client.BaseChart::nativeAddSeries(Lcom/google/gwt/
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
下面是我的代码(在循环中运行):
正如我之前所说,前两个系列还可以,但第三个系列抛出了上述异常(当我调试应用程序时,我可以看到新创建的yAxis引用)
下面是引发异常的行:
chart.addSeries(newSeries.setName("Test " + index));
谢谢请检查索引值。 如果索引大于轴计数,则可能发生此错误 highcharts错误#18表示尝试访问的轴不存在 这里是链接
希望这能对你有所帮助我终于明白了 这似乎是个问题。它根本不会将新的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);
以下是此类错误的原因: 如果您使用的是包装器,则必须在将图表添加到DOM之前进行配置!在将其添加到DOM之后,任何配置更改似乎都不起作用
快乐编码 如果你没有添加第三个系列,你得到图表了吗?Highcharts错误#18:请求的轴不存在。您在同一行中调用了两次
.setPlotLines()
。一次有选择,另一次没有选择。可以吗?谢谢@AntoJurković的快速评论:)如果我不添加第三个系列,它几乎没问题(但有时我会在范围选择栏中看到第二个系列!)顺便说一句,我删除了.setPlotLines()
的无参数调用,但没有任何更改。我检查了索引值,没有任何错误。实际上,当我调试应用程序时,我可以在图表实例中看到新创建的轴,但当我尝试添加序列时,它找不到关联的轴(但它在那里,我可以在调试模式下看到)
// 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);