I have a GWT application which display severals chart with gwt-visualization.
I want in my ColumnChart
the value of the column inside it.
In the official documentation, we can see that with DataView
we can add the value inside a column:
https://developers.google.com/chart/interactive/docs/gallery/columnchart
(please see the type of graph that i want before "This is a little more complicated than it should be, because we create a DataView
to specify the annotation for each column.")
Here my actual code wich display the value only when we hover the column:
ColumnChart col = new ColumnChart(createColTable(), createColOptions());
fp.add(col);
private AbstractDataTable createColTable() {
int maxNbLines = 5;
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, messages.user());
data.addColumn(ColumnType.NUMBER, messages.nbMsg());
data.addColumn(ColumnType.NUMBER, messages.nbTot());
data.addRows(maxNbLines);
if (this.getMetrics().size() > 0) {
int j = 0;
for (java.util.Map.Entry<String,UIMetricsBean> entry :
this.getDayMetrics().entrySet()) {
String key = entry.getKey();
UIMetricsBean value = entry.getValue();
data.setValue(j, 0, key);
data.setValue(j, 1, value.getNbTotal());
data.setValue(j, 2, value.getNbBad());
j++;
if(j >= maxNbLines) {
break;
}
}
}
return data;
}
private Options createColOptions() {
TextStyle titleTextStyle = TextStyle.create();
titleTextStyle.setFontSize(18);
titleTextStyle.setColor(COLOR_RED);
Options options = Options.create();
options.setWidth(720);
options.setHeight(350);
options.setTitle(messages.tot());
options.setColors(COLOR_GRAY, COLOR_RED);
options.setBackgroundColor(COLOR_BACKGROUND_GRAY);
TextStyle axisTextStyle = TextStyle.create();
axisTextStyle.setFontSize(8);
HorizontalAxisOptions hAxisOption = HorizontalAxisOptions.create();
hAxisOption.setTextStyle(axisTextStyle);
options.setHAxisOptions(hAxisOption);
options.setTitleTextStyle(titleTextStyle);
return options;
}
Do you know how i can display the value of the column inside the column?
Thanks!
You can achieve this using JSNI and annotation. Here is a working example. You still need to pass your data as an Array to JSNI.
The result