gwt - HighCharts 股票图表错误代码 18

标签 gwt highcharts 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/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));

谢谢

最佳答案

我终于明白了!

GWT-HighCharts似乎是问题所在。它根本不会将新的 YAxis 添加到图表中。因此,您必须通过 native 调用添加 YAxis,如下所示;

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

只需在添加新系列之前调用此 native 方法即可。

            // 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);

关于gwt - HighCharts 股票图表错误代码 18,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20618155/

相关文章:

mysql - 将数据库统计数据绘制到网页上的快速方法

GWT 图像按钮

Javascript Highcharts 重命名或删除图表中的系列标签

javascript - highcharts:动态定义饼图中的颜色

javascript - 将 Highcharts 与 Curljs 集成的最佳方式是什么?

javascript - GWT Highcharts - 禁用系列动画

java - 自定义小部件扩展文本字段

java - 在GWT中添加html和java脚本代码

css - 在 Vaadin 应用程序中应用 Css 样式