Bar Chart Double Precision

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
javier_alexander
Posts: 2
Joined: Tue Nov 24, 2015 7:13 am
antibot: No, of course not.

Bar Chart Double Precision

Post by javier_alexander » Tue Nov 24, 2015 7:41 am

Hi, I am using JFreeChart in my project and I have encountered a problem.
At the beginning, if I create a bar chart the values set with

Code: Select all

dataset.setValue(tempMoney, "Money", tempName);
will all be 0.00 because that's how they are initialized in my program, but in the chart it shows from 0.000000005 to -0.000000005. My problem is I don't know how to:

1. Make it show only 2 decimal places.
2. Make it start from 0.00 and then only go up, as I will not have any negative values.

If I later on change some of the values it does show only from 0.00 to the highest new value with only 2 decimal places.

I have tried with the following:

Code: Select all

while( i < (workerArray.size()) )
        {
            tempName=workerArray.get(i).getName();
            tempMoney=workerArray.get(i).getMoney();
            if (tempMoney == 0.00)
            {
                dataset.addValue(0, "Money", tempName);
            }
            else
            {
                dataset.setValue(tempMoney, "Money", tempName);
            }
            i++;
        }
but it still shows 9 decimal places. I have looked at the api documentation but I find it confusing. Any help will be appreciated!

Naxter
Posts: 45
Joined: Thu Jun 26, 2014 8:24 am
antibot: No, of course not.
Location: Germany, Aachen

Re: Bar Chart Double Precision

Post by Naxter » Tue Nov 24, 2015 8:26 am

At first you maybe should post a screenshot of what exactly your problem is.

If I understand you right, you would like to decide yourself how the Y-Axis is shown?

You can recieve this by doing this:

Code: Select all

XYPlot plot = getXYPlot();
NumberAxis axis = new NumberAxis();
axis.setRange(lower, upper);
plot.setRangeAxis(axis);

javier_alexander
Posts: 2
Joined: Tue Nov 24, 2015 7:13 am
antibot: No, of course not.

Re: Bar Chart Double Precision

Post by javier_alexander » Tue Nov 24, 2015 9:26 am

Naxter wrote:At first you maybe should post a screenshot of what exactly your problem is.

If I understand you right, you would like to decide yourself how the Y-Axis is shown?

You can recieve this by doing this:

Code: Select all

XYPlot plot = getXYPlot();
NumberAxis axis = new NumberAxis();
axis.setRange(lower, upper);
plot.setRangeAxis(axis);
Thanks for replying. Your answer was REALLY helpful.
I wanted to display only 2 decimals as opposed to the 9 that appeared when all my values were 0.00
However when I used your code it always showed from whatever I set my lower to be up to whatever I set my upper to be. I solved that with this:

Code: Select all

JFreeChart chart = ChartFactory.createBarChart3D("Money Bar Chart", "Name", "Money", dataset, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p=chart.getCategoryPlot();
        if (maxMoney == 0.00)
        {
            NumberAxis axis = new NumberAxis();
            axis.setRange(0, 5);
            p.setRangeAxis(axis);
        }
        p.setRangeGridlinePaint(Color.BLUE);
        p.setNoDataMessage("File hasn't been loaded");
        ChartFrame frame = new ChartFrame("Money Bar Chart", chart);
        frame.setVisible(true);
        frame.setSize(850,350);
that way, when all my values are 0.00 it shows from 0 to 5 and when I have other values it shows from 0 up to the biggest number, which is the result that I wanted.
Thanks again for the help :)

Naxter
Posts: 45
Joined: Thu Jun 26, 2014 8:24 am
antibot: No, of course not.
Location: Germany, Aachen

Re: Bar Chart Double Precision

Post by Naxter » Tue Nov 24, 2015 10:06 am

I am glad that I was able to help you.
Happy coding.

Locked