Resizing the JFreeChart Bar-Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
yubraz
Posts: 3
Joined: Thu Mar 19, 2015 12:47 am
antibot: No, of course not.

Resizing the JFreeChart Bar-Chart

Post by yubraz » Thu Mar 19, 2015 7:21 am

I am trying to re-size the width and length of the Bar-Chart so that all the data in the chart gets displayed properly without overlapping the bar values.
I tried the following

chart = ChartFactory.createBarChart(sysName+" Report", "Day", msMasterCustomizedVO.getValue(), dataset, PlotOrientation.VERTICAL, true, true, false);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(900, 450));
AND
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setMaximumDrawWidth(900);
chartPanel.setMinimumDrawWidth(800);

Above code did not do anything.

I have attached 3 images which shows data on hourly, daily and monthly basis.
The data gets generated based on the criteria we select and it automatically populates 800 x 400 size.

For the hourly image the data is not overlapped because hr 0-24 on x-axis easily fits the graph size and no overlapping occurs.

For the daily image the data is being overlapped because day 1-31(depending on the no of days of month) the bars sets its width automatically to fit in all days.
I want to apply the re-sizing to this portion only and the above mentioned code did not work.

For the monthly image the data is not overlapped because months 1-12 are present on x-axis which is a less number, and the width of the bar increase auto to match the value.
I noticed that the value is higher than the y-axis range here, it may be due to the graph being too small to provide more y-axis range. Can someone help me with this also.

Hourlyhttp://postimg.org/image/8ghxq9w2d/
Daily http://postimg.org/image/hqpwzfiux/
Monthly http://postimg.org/image/624hmhth7/

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Resizing the JFreeChart Bar-Chart

Post by paradoxoff » Thu Mar 19, 2015 12:52 pm

I can´t imagine a straightforward way to automaticall resize the chart in such a way that the bar labels do not overlap.
Have you thought about using a smaller font for the labels or displaying ther labels in a vertical orientation?

yubraz
Posts: 3
Joined: Thu Mar 19, 2015 12:47 am
antibot: No, of course not.

Re: Resizing the JFreeChart Bar-Chart

Post by yubraz » Thu Mar 19, 2015 2:23 pm

What i was thinking was if reisze the chart for daily period it would increase the chart range and value would not overlap. But Yes i can try changing the font too.

How do i decrease the font of labels for period daily only.

Sorry i am new to the jfreechart and UI stuffs.
Any directions :)

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Resizing the JFreeChart Bar-Chart

Post by paradoxoff » Fri Mar 20, 2015 4:32 pm

yubraz wrote:What i was thinking was if reisze the chart for daily period it would increase the chart range and value would not overlap.
What is the "chart range" that should automagically increase ? What exactly are you doing when you "resize the chart"? Changing its physical size or just changeing the time range that is shown?
To change the font for the label on the bar, you can call setBaseItemLabelFont(java.awt.Font font) on your renderer. You can get the renderer by calling chart.getCategoryPlot().getRenderer(). That should work.
Note that you will have to change the font explicitly, whenever you are changing between one of the views (hourly, daily, monthly).

Locked