Menu

Can't get the Yaxis data of Point in tooltipdata in Stock Chart.

XiGuan
2012-01-17
2012-07-13
  • XiGuan

    XiGuan - 2012-01-17

    Hi , I faced this problem when I tried to create a Stock table with tooltip

    This is the code I am using

            final StockChart stockChart = new StockChart()  
            .setToolTip(new ToolTip()  
                .setFormatter(new ToolTipFormatter() {  
                    public String format(ToolTipData toolTipData) {
                        String dateString=DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss")  
                            .format(new Date(toolTipData.getXAsLong())) 
                            + toolTipData.getYAsDouble();
                        return dateString;
                    }  
                })  
            );
    

    And this is the code I am using to add series to the chart.

        final Series series = stockChart.createSeries();  
            stockChart.addSeries(series.setName("Random data"));  
            long time = new Date().getTime();  
            for(int i = -19; i <= 0; i++) {  
                series.addPoint(time + i * 1000, com.google.gwt.user.client.Random.nextDouble());  
            }
    

    When I run it in GWT development mode, I found the tool tip is not display, and when opening the Javascript console, I found the error as below:
    "Uncaught com.google.gwt.dev.shell.HostedModeException: Something other than a double was returned from JSNI method '@org.moxieapps.gwt.highcharts.client.ToolTipData::getYAsDouble()': JS value of type undefined, expected double."
    Below that, there is another line which said: " event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future."

    When I removed the code "NumberFormat.getFormat("0.00").format(toolTipData.getYAsDouble())", the tool tip is showing.

    Does anyone know what's going on here ?

    The highstock.js I am using is version 1.1.2.
    The moxie highchart gwt I am using is 1.1.3
    GWT SDK is 2.4.0

     

    Last edit: XiGuan 2012-01-17
  • Shawn Quinn

    Shawn Quinn - 2012-01-18

    It looks like stock charts have tooltips running in "shared" mode by default, so you'll need to use the ToolTipData's "getXAsLong(int index)" and "getYAsDouble(int index)" (or take the tooltip out of shared mode.) Here's a working example:

    final StockChart stockChart = new StockChart()
        .setToolTip(new ToolTip()
            .setEnabled(true)
            .setFormatter(new ToolTipFormatter() {
                public String format(ToolTipData toolTipData) {
                    String dateString = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss")
                        .format(new Date(toolTipData.getXAsLong(0))) + " " +
                        toolTipData.getYAsDouble(0);
                    return dateString;
                }
            })
        );
    final Series series = stockChart.createSeries();
    stockChart.addSeries(series.setName("Random data"));
    long time = new Date().getTime();
    for (int i = -19; i <= 0; i++) {
        series.addPoint(time + i * 1000, com.google.gwt.user.client.Random.nextDouble());
    }
    

    Can you let us know if the clears up the problem you're seeing?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.