2

我正在尝试使用 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/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));

正如我之前所说,前两个系列没问题,但第三个系列抛出上述异常(当我调试应用程序时,我可以看到新创建的 yAxis 引用)。

这是引发异常的行:

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

谢谢

4

3 回答 3

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);
于 2013-12-17T12:05:25.703 回答
2

以下是此类错误的原因:

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

快乐编码!

于 2013-12-28T16:34:55.033 回答
1

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

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

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

希望对你有帮助

于 2013-12-17T05:10:43.667 回答