Hi All,
My application needs to maintain a constant Barwidth irrespective of the size of the Graph. As there is no method to set the Bar Width (setBarWidth() method is protected) I did the following as a work around.
Snippet of the code to maintain constant BarWidth:
int barWidth = 50;
int totalMargin = lowerCategoryMargin + upperCategoryMargin;
int categoryCount = dataSet.getColumnCount();
int seriesCount = dataSet.getRowCount();
if(categoryCount > 1) {
totalMargin += categoryMargin;
}
if(seriesCount > 1) {
totalMargin += itemMargin;
}
int width = totalMargin + barWidth * seriesCount * categoryCount;
if(categoryCount > 1) {
domainAxis.setCategoryMargin((double)(categoryMargin * (categoryCount - 1))/width);
}
domainAxis.setLowerMargin((double)lowerCategoryMargin/width);
domainAxis.setUpperMargin((double)upperCategoryMargin/width);
int totalWidth = width + 50;
where 50 is some constant value to take care of plot area width which is outside the data area width.
But unfortunately this is not working. Every time barwidth is varying based on the Graph size. I dont mind if the barwidth varies by + or - 3 pixels. But it varies by + or - 15 pixels.
Is there anything wrong in my code or is their any simple way.
Please help me.
Thanks and Regards,
Narasimha
How to maintain constant Bar Width in Vertical Bar Chart 3D.
Re: How to maintain constant Bar Width in Vertical Bar Chart
JFreeChart is designed to draw charts at arbitrary sizes, so the bar width calculation always adjusts to fit the available space. There is no easy way to make the bars a fixed width.
Regards,
Dave Gilbert
Regards,
Dave Gilbert