Need help with Logarithmic x-axis.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
pl477150
Posts: 12
Joined: Tue Oct 04, 2016 6:20 pm
antibot: No, of course not.

Need help with Logarithmic x-axis.

Post by pl477150 » Tue Oct 04, 2016 6:49 pm

Hello everyone.

I have been trying to get a chart with a specific look using a logarithmic x-axis. I need it to look something like this:
Image

The closest I have been able to create is this:
Image

Here is the code I am using:

Code: Select all

XYPlot plot = chart.getXYPlot();
LogAxis domainAxis = new LogAxis("x-axis");
domainAxis.setBase(10);
domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
NumberAxis rangeAxis = new NumberAxis("y-axis");
plot.setDomainAxis(domainAxis);
plot.setRangeAxis(rangeAxis);
chart.setBackgroundPaint(Color.white);
plot.setOutlinePaint(Color.black);
ChartPanel chartPanel = new ChartPanel(chart);
I am mostly wanting to have the vertical gridlines displayed showing the logarithmic scale is being used and having the values on the x-axis in integer format instead of exponential.
I am also wondering why the 1000 to 10000 range is curved instead of being a line. As far as I can see my data is correct at the random places I have sampled it.

Any help would be greatly appreciated.
PL

pl477150
Posts: 12
Joined: Tue Oct 04, 2016 6:20 pm
antibot: No, of course not.

Re: Need help with Logarithmic x-axis.

Post by pl477150 » Wed Oct 05, 2016 1:54 pm

I have done a lot more testing with the data and it is off a bit in some places, so the curve in the graph may be caused by that.

I would still like to change the tick values in the x-axis to something more like "10, 100, 1000, 10000, 100000, etc..." Would it be something to change with the "tick unit"?

PL

pl477150
Posts: 12
Joined: Tue Oct 04, 2016 6:20 pm
antibot: No, of course not.

Re: Need help with Logarithmic x-axis.

Post by pl477150 » Wed Oct 05, 2016 2:21 pm

After further review and pulling my head out of my butt, and then pulling my foot out of my mouth, I have realized I need a logarithmic scale for both axes. Now my graph looks like this:
Image

Now I just have to figure out how to change the tick labels and I should be good.

pl477150
Posts: 12
Joined: Tue Oct 04, 2016 6:20 pm
antibot: No, of course not.

Solved - Re: Need help with Logarithmic x-axis.

Post by pl477150 » Wed Oct 05, 2016 4:31 pm

I think I have found a solution to this. Posting this in case it helps someone else.

The graph is looking like this now:
Image

This is the code:

Code: Select all

XYPlot plot = chart.getXYPlot();
LogAxis domainAxis = new LogAxis("X-axis");
domainAxis.setBase(10);
domainAxis.setNumberFormatOverride(NumberFormat.getNumberInstance());
domainAxis.setMinorTickMarksVisible(true);
LogAxis rangeAxis = new LogAxis("Y-axis");
rangeAxis.setBase(10);
rangeAxis.setNumberFormatOverride(NumberFormat.getNumberInstance());
rangeAxis.setMinorTickMarksVisible(true);
plot.setDomainAxis(domainAxis);
plot.setRangeAxis(rangeAxis);
chart.setBackgroundPaint(Color.white);
plot.setOutlinePaint(Color.black);
plot.setDomainMinorGridlinesVisible(true);
plot.setRangeMinorGridlinesVisible(true);
ChartPanel chartPanel = new ChartPanel(chart);

Locked