How to change grid size in gwt-visualization's LineChart?

495 views Asked by At

I am using the 1.1.1 release of gwt-visualization. Here is what I got so far:

final DataTable dataTable;
// creation of the data table left out ..

final Options options = Options.create();

final HorizontalAxisOptions horizontalAxisOptions = HorizontalAxisOptions.create();
horizontalAxisOptions.setShowTextEvery(1);

// ... ?

options.setHAxisOptions(horizontalAxisOptions);

LineChart lineChart = new LineChart(dataTable, options);
2

There are 2 answers

0
Jens Piegsa On BEST ANSWER

The Options.set(key, value)-method(s) generally does the job. However, instead of using the dot notation, one must create nested Options objects (or create wrapper classes like HorizontalAxisOptions).

But: There's an issue for date values.

A workaround for this might be the usage of minorGridlines. I suspect that I'll end up in an ugly date calculation. :-(

Other suggestions?

0
Michael On

You need to use the set method but nest options. For example

    Options options = Options.create()  //Main option
    Options Haxis = Options.create();
    Options Hgrid = Options.create();
    Hgrid.set("count", 12d);
    Haxis.set("gridlines", Hgrid);
    options.set("hAxis", Haxis);

    Options series_options = Options.create();
    Options series1_options = Options.create();
    series1_options.set("color","#CE5C0A");
    Options series2_options = Options.create();
    series2_options.set("color","blue");
    Options series3_options = Options.create();
    series3_options.set("color","#6600CC");
    Options series4_options = Options.create();
    series4_options.set("color","#00FF00");
    series_options.set("0",series1_options);
    series_options.set("1",series2_options);
    series_options.set("2",series3_options);
    series_options.set("3",series4_options);
    options.set("series",series_options);

The first block I nested options to set the hAxis.gridlines.count parameter to 12.

The second block I nested a lot of options to set the color of the series.