HighCharts-GXT/GWT Project The official HighCharts-GWT/GXT adapters blog

Managing Sections

Adding options

The execution of the following code:

hc.setOption(new OptionPath("/plotOptions/spline/marker/enabled"), true);
hc.setOption(new OptionPath("/plotOptions/spline/marker/radius"), 4);
hc.setOption(new OptionPath("/plotOptions/spline/marker/lineColor"), "#666666");
hc.setOption(new OptionPath("/plotOptions/spline/marker/lineWidth"), 1);

will generate the following JS structure:

 plotOptions: {
  spline: {
    marker: {
      enabled: true,
      radius: 4,
      lineColor: '#666666',
      lineWidth: 1
    }
  }
}

An alternative way

Another more compact solution to store sub-options of a given path.
Using maps to insert a subtree of options (e.g. /plotOptions/spline/marker)

HashMap<String, Object> optsMap = new HashMap<String, Object>();
optsMap.put("enabled", true);
optsMap.put("radius", 4);
optsMap.put("lineColor", "#666666");
optsMap.put("lineWidth", 1);
hc.setOption(new OptionPath("/plotOptions/spline/marker"), optsMap);

 

Removing options

An option can be removed from the section as follows:

  hc.removeOption(new OptionPath("/plotOptions/spline/marker/enabled"));

the result will be:

plotOptions: {
  spline: {
    marker: {
      radius: 4,
      lineColor: '#666666',
      lineWidth: 1
    }
  }
}

while executing:

hc.removeOption(new OptionPath("/plotOptions/spline/marker"));

the subtree marker will be pruned:

plotOptions: {
  spline: {
  }
}

Getting value of an Option

Considering the first tree

hc.getOption(new OptionPath("/plotOptions/spline/marker/enabled"));

will return a Boolean with value true

while the execution of:

hc.getOption(new OptionPath("/plotOptions/spline/marker"));

will return a Map with keys: enabled, radius, ...

finally the execution of:

hc.getOption(new OptionPath("/plotOptions/area/marker/enabled"));

will throw an exception since the option is not defined