Menu

How to get the ohlc value from tool tip ?

XiGuan
2012-01-30
2012-07-13
  • XiGuan

    XiGuan - 2012-01-30

    The code I am using is like below:

    stockChart.setToolTip(new ToolTip().setShared(false)
            .setFormatter(new ToolTipFormatter() {
                public String format(ToolTipData toolTipData) {
                    Point tempPoint=toolTipData.getPoint();
                    String openString="open: "+tempPoint.getOptions().get("open").isNumber().doubleValue();
                    String highString="high: "+tempPoint.getOptions().get("high").isNumber().doubleValue();
                    String lowString="low: "+tempPoint.getOptions().get("low").isNumber().doubleValue();
                    String closeString="close: "+tempPoint.getOptions().get("close").isNumber().doubleValue();
    
                    return  "<b>"+openString+"</b><br>"
                            +"<b>"+highString+"</b><br>"
                            +"<b>"+lowString+"</b><br>"
                            +"<b>"+closeString+"</b><br>";
                }
            }));
    

    I found the main problem is the return value of getOptions() is null. The reason causing this is : options is one private variable of Configurable class; Point class is the subclass of Configurable class. So options variable is not accessible for the instance of Point class.

    Does anyone do the similar thing before ?

     
  • Shawn Quinn

    Shawn Quinn - 2012-02-01

    Better support for OHLC charts has been added to GWT Highcharts and is coming in the next release (version 1.2.0). In the meantime though, in order to accomplish this you'll need to add a method like the following to the "org.moxieapps.gwt.highcharts.client.Point" class:

        public Number getOpen() {
            if (this.nativePoint != null) {
                return nativeGetNumber(this.nativePoint, "open");
            }
        }
    

    And a similar "getHigh", "getLow", and "getClose" method. Can you give that a shot and let us know if that accomplishes what you need in your custom tooltip formatter?

     
  • Shawn Quinn

    Shawn Quinn - 2012-02-20

    FYI - Better support for OHLC charts has now been added to GWT Highcharts with the 1.2.0 release. So, you can now setup data points with OHLC (open/high/low/close) data using the new Point constructor like so:

    chart.addSeries(chart.createSeries()
        .setName("OHLC Data Points")
        .setPoints(new Point[]{
            new Point(1, 10, 15, 8, 12),
            new Point(2, 12, 13, 6, 13),
            new Point(3, 13, 16, 11, 15)
        })
    );
    

    Or, just as a raw two dimensional numeric data array, where each inner array specifies the OHLC data as the second, third, fourth, and fifth elements like so:

    chart.addSeries(chart.createSeries()
        .setName("OHLC Data Points")
        .setPoints(new Number[][] {
            {1, 110, 115, 18, 112},
            {2, 112, 113, 16, 113},
            {3, 113, 116, 111, 115}
        })
    );
    
     

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.