1

I'm using google visualisations to create a combo chart in a GWT application, and I would like to set the maximum value of the vertical axis manually. I have found posts that tell me how to do this in javascript, for example Setting a hard minimum axis value in Google Charts API, and these say I need to set the viewWindow. I cannot however work out how to do this in Java. I currently have this method to get the chart options:

private static Options createOptionsChart() {
    Options options = Options.create();
    options.setWidth(800);
    options.setHeight(600);
    if (max > 0) {
        options.setVAxisOptions(getAxisOptions());
    }

    options.set("isStacked", true);
    options.set("legend", "none");

    return options;
}

and this method to get the axis options:

    private static AxisOptions getAxisOptions() {
    AxisOptions ao = AxisOptions.create();
    ao.set("viewWindowMode", "explicit");
    ao.set("viewWindow.max", max);

    return ao;
}

Running this however I get a runtime error message in my browser of

Option "viewWindowMode" was set to "explicit" but "viewWindow" was not specified

I cannot seem to find a way to specify the viewWindow - I have tried setting it to a new JavaScriptObject, a object that extends JavaScriptObject...

If anyone has any suggestions I would be most grateful.

Community
  • 1
  • 1
Mahana
  • 128
  • 1
  • 8

1 Answers1

1

This should work:

 private static AxisOptions getAxisOptions() {
    AxisOptions ao = AxisOptions.create();
    ao.set("viewWindowMode", "explicit");
    Options viewWindowOption = Options.create();
    viewWindowOption.set("max",max);
    ao.set("viewWindow",viewWindowOption);
    return ao;
}
Ümit
  • 17,379
  • 7
  • 55
  • 74