change the width of the bar in barchart rendered as a .png
-
- Posts: 7
- Joined: Sat Aug 04, 2007 1:29 pm
change the width of the bar in barchart rendered as a .png
hi all
I am new to jfree charts . I am using a simple barchart for displaying the values . but iam not able to change the width of the bar . I am using setMaxBarWidth method but it is not causing any change .. can anybody please help me in this regard
I am new to jfree charts . I am using a simple barchart for displaying the values . but iam not able to change the width of the bar . I am using setMaxBarWidth method but it is not causing any change .. can anybody please help me in this regard
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: change the width of the bar in barchart rendered as a .p
setMaximumBarWidth() sets the maximum bar width to be a fixed percentage of the available plot area--not a physical size for the bars. A common error is to put a value greater than 1.0 (100%) which causes no visible effect on the size of the bars because the default is 1.0. Try setting the maximum width to 0.01 (1%), and you should notice the difference. In contrast, setMinimumBarWidth() takes an absolute pixel value.raghuseeta wrote:I am using setMaxBarWidth method but it is not causing any change .. can anybody please help me in this regard
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 7
- Joined: Sat Aug 04, 2007 1:29 pm
Width of bar in a .png
Hi,
Thanks for the response.... I am plotting 4 different series with number of bars in each series and I am rendering the chart as a .png of fixed size.
How do I set the width of the individual bars in each series?
[/img][/code]
Thanks for the response.... I am plotting 4 different series with number of bars in each series and I am rendering the chart as a .png of fixed size.
How do I set the width of the individual bars in each series?
[/img][/code]
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
For XYBarRenderer, the bar width comes from the starting and ending x-values specified in the dataset (IntervalXYDataset). Which implementation of IntervalXYDataset are you using?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 7
- Joined: Sat Aug 04, 2007 1:29 pm
Thank you gilbert sir for taking notice of my query.
I am not using XYBarRenderer . I am using BarRenderer.The code snippet what i am using to genereate BarChart is as follows
I am using the above code in my bean class which generates the png image and getting displayed thru a servlet ... even though i am trying to change the width of each individual bar giving several combinations of values from 0.01 to 1.0 to renderer.setMaxBarWidth(widthvalue) it is not taking effect in the .png image getting displayed in the jsp.. please help me out with this..
I am not using XYBarRenderer . I am using BarRenderer.The code snippet what i am using to genereate BarChart is as follows
Code: Select all
String category1= "category1";
String category2= "category2";
String category3= "category3";
String category4= "category4";
DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
for(int k=0; k<list1.size(); k++) {
// populate the dataset
dataset1.addValue( ..seriesvalues.. , category1);
}
for(int k=0; k<list2.size(); k++) {
// populate the dataset
dataset1.addValue(..seriesvalues.. ,category2);
}
for(int k=0; k<list3.size(); k++) {
// populate the dataset
dataset1.addValue(..seriesvalues.. , category4);
}
for(int k=0; k<list4.size(); k++) {
// populate the dataset
dataset1.addValue(..seriesvalues.. , category5);
}
// each list contains the datas for each series
BarRenderer renderer = new BarRenderer();
renderer.setSeriesFillPaint(1, Color.black);
renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
//[b] changing the length of the bar [/b]
renderer.setMaxBarWidth(0.01);
final CategoryPlot plot = new CategoryPlot();
plot.setDataset(0,dataset1);
plot.setRenderer(0,renderer);
NumberAxis numberAxis = new NumberAxis("Scores");
numberAxis.setLabelFont(new Font("Arial",Font.PLAIN,13));
numberAxis.setTickLabelFont(new Font("Arial",Font.PLAIN,15));
numberAxis.setTickUnit(new NumberTickUnit(10.0));
numberAxis.setRange(0.0, 100.0);
renderer.setItemURLGenerator(new StandardCategoryURLGenerator("","series",""));
renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryAxis categoryAxis = new CategoryAxis("");
categoryAxis.setTickLabelFont(new Font("Arial",Font.PLAIN,15));
categoryAxis.setTickMarkInsideLength(10.0f);
plot.setDomainAxis(categoryAxis);
plot.setRangeAxis(numberAxis);
plot.setOrientation(PlotOrientation.VERTICAL);
plot.setRangeGridlinesVisible(true);
plot.setDomainGridlinesVisible(true);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
JFreeChart chart = new JFreeChart(plot);
chart.setTitle("ABC Chart");
LegendItemCollection result = new LegendItemCollection();
LegendItem LegendItem1 = new LegendItem(new AttributedString("Legend1"), "description 0", "tooltip 0", "url 0", new Rectangle2D.Double(-4.0,-4.0,8.0,8.0),Color.red);
LegendItem LegendItem2 = new LegendItem(new AttributedString("Legend2"), "description 1", "tooltip 1", "url 1", new Rectangle2D.Double(-4.0,-4.0,8.0,8.0),Color.yellow);
LegendItem LegendItem3 = new LegendItem(new AttributedString("Legend3"), "description 2", "tooltip 1", "url 1", new Rectangle2D.Double(-4.0,-4.0,8.0,8.0),Color.blue);
LegendItem LegendItem4 = new LegendItem(new AttributedString("Legend4"), "description 3", "tooltip 1", "url 1", new Rectangle2D.Double(-4.0,-4.0,8.0,8.0),Color.green);
result.add(LegendItem1);
result.add(LegendItem2);
result.add(LegendItem3);
result.add(LegendItem4);
plot.setFixedLegendItems(result);
chart.setBackgroundPaint(Color.white);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, 800, 286, info, session);
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
With the regular BarRenderer, you don't get to specify the bar width. JFreeChart calculates the bar width according to the number of bars to be displayed, the plot width, the lower and upper margins on the axis, the margin between categories and the margin between items within each category.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

