Menu

Awkward way to have legend-less chart

2011-11-01
2012-07-20
  • rob walker

    rob walker - 2012-07-19

    Can this be done dynamically. I get a legend-less chart fine if I do this at chart create time, but setting enabled false once rendered doesn't seem to "hide" an already displayed legend.

     
  • rob walker

    rob walker - 2012-07-19

    Highcharts have come back with a way to do this in JS:

    $('#b0').click(function() {
        console.log(chart);
        chart.legend.box.hide();
        chart.legend.group.hide();
        chart.legend.display = false;
        chart.series[0].show(false);
    });
    $('#b1').click(function() {
        chart.legend.box.show();
        chart.legend.group.show();
        chart.legend.display = true;
        chart.series[0].show(false);
    

    But I can't see any GWT bindings in the moxie layer that would let me do an equivalent from Java?

     
  • rob walker

    rob walker - 2012-07-19

    With help from the Highcharts guys - I managed to get dynamic enable/disable of legends working. It needs some native code:

        public static native void nativeEnableLegend(JavaScriptObject chart, boolean show) /*-{
    
            if (show) {
                chart.legend.box.show();
                chart.legend.group.show();
                chart.legend.display = true;
                chart.series[0].show(false);
            } else {
                chart.legend.box.hide();
                chart.legend.group.hide();
                chart.legend.display = false;
                chart.series[0].show(false);
            }
        }-*/;
    

    Which you then call from your Java code e.g.

        nativeEnableLegend(myChart.getNativeChart(), false);
    

    The original JS fiddle example they sent me is here:

    http://jsfiddle.net/5m9JW/162/

    Note that the above needed Highstock 1.1.6 to work. Superficially it seems ok with current GWT wrapper although there could be incompatibilities I haven't noticed yet.

     
  • Shawn Quinn

    Shawn Quinn - 2012-07-19

    Yeah, what you did there should work well with GWT Highcharts. If/when the Highcharts guys add a specific API method to enable/disable the legend on the fly, we can get an equivalent wrapper method added to GWT Highcharts.

    Thanks for posting your solution!

     
  • rob walker

    rob walker - 2012-07-20

    Welcome.

    Overall Highstock 1.1.6 seems to work in place of 1.1.5 in current release. Have observed one oddity where a stacked area plot has color fill on first plot, but on later the fill seems to get lost and just show stacked lines with a white fill.

     

Log in to post a comment.