PDA

View Full Version : Separate x_label from tool tip for charts



babyblue
21 Jan 2010, 6:08 PM
Right now tool tip for my charts is something like "#x_label#: #val#", and I'm using DataProvider to manage the data model. Problem is sometimes the labels are very long, so I would like to truncate them on the X axis, but not in the tool tip. I figured out that I can override DataProvider.getLabel(), but that will change both the axis and the tool tip.




ColoredBarDataProvider barProvider = new ColoredBarDataProvider(model.getValueColumnID(), model.getLabelColumnID(), model.getLabelColumnID());
barProvider.useColor = true;
barProvider.bind(store);

BarChart barChart = new BarChart(BarStyle.NORMAL);
barChart.setTooltip("#x_label#: #val#");
barChart.setDataProvider(barProvider);
chartModel.addChartConfig(barChart);




static class ColoredBarDataProvider extends BarDataProvider{
@Override
protected String getLabel(ModelData model, String valueProperty) {
String label = super.getLabel(model, valueProperty);
ChartModel chartModel = chartConfig.getModel();
if(chartModel instanceof CustomChartModel){
return ((CustomChartModel)chartModel).formatLabel(label);
}
return label;
}
}