| | | | Browse by category |
Question
Why an empty chart is displayed when the chart contains only one data point with the bar renderer?
Answer
In order to display a data point, the bar renderer must calculate the width and height of the bar using the x and y axis data range, respectively. When there is only one data point (0, 10) in the data source, the data range of the x-axis is [0,0] and y-axis is [10,10]. With both data ranges being 0, an empty chart will be displayed. You can display a bar for the single data point chart in the following ways:
- By explicitly set the data range for both x and y axis using the following methods:
- IlvChart.getXAxis()
- lvChart.getYAxis(int index)
- IlvAxis.setDataRange(int min, int max)
- IlvAxis.setDataRange(IlvDataInterval range)
- By setting your own data range policy to the chart.
chart.setDataRangePolicy (new IlvDefaultDataRangePolicy (){
public IlvDataInterval computeDataRange(IlvChart chart,
IlvAxis axis, IlvDataInterval retRange) {
if( retRange != null && retRange.getLength() == 0 )
// return your own data interval that contains the data point.
else
return super.computeDataRange( chart, axis, retRange );
}
}