irregular spaced tick marks but with sequential number xaxis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).

irregular spaced tick marks but with sequential number xaxis

Postby topher » Thu May 12, 2016 11:40 pm

I'm trying to make a jfreechart graph with tick marks, on the x-axis, that are sequential in number but are irregularly spaced.
see: http://www.pingfire.com/graph185.aspx

I've tried LogAxis and LogarithmicAxis, I need the reverse.

test code in full:

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Stroke;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.XYLineAnnotation;
import org.jfree.chart.axis.LogarithmicAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;

public class Stuff extends ApplicationFrame
{

public Stuff(final String title)
{
super(title);

XYSeries rawDataSeries = new XYSeries("1");
rawDataSeries.add(1, 66);
rawDataSeries.add(787, 55);

XYSeries rawTheoretical = new XYSeries("2");
rawTheoretical.add(787, 55);
rawTheoretical.add(7000, 20);

XYSeries safetyDataSeries = new XYSeries("3");
safetyDataSeries.add(1, 59);
safetyDataSeries.add(787, 48);

XYSeries safetyTheoretical = new XYSeries("4");
safetyTheoretical.add(787, 48);
safetyTheoretical.add(6000, 20);

XYSeriesCollection totalChartData = new XYSeriesCollection();
totalChartData.addSeries(rawDataSeries);
totalChartData.addSeries(rawTheoretical);
totalChartData.addSeries(safetyDataSeries);
totalChartData.addSeries(safetyTheoretical);


Stroke stroke = new BasicStroke(1.0f);
XYLineAnnotation flowLine = new XYLineAnnotation(787, 0.0, 787, 55, stroke, Color.DARK_GRAY);
boolean legend = true;
boolean tooltip = true;
boolean url = false;
JFreeChart flowChart = ChartFactory.createXYLineChart("", "Flow (GPM)", "Pressure (PSI)", totalChartData, PlotOrientation.VERTICAL, legend, tooltip, url);

// graph properties
RectangleInsets chartRectangle = new RectangleInsets(10F, 5F, 5F, 20F);
flowChart.setPadding(chartRectangle);
flowChart.setBorderPaint(Color.black);
flowChart.setBorderStroke(new BasicStroke(1));
flowChart.setBorderVisible(true);

// plot properties
XYPlot plot = (XYPlot) flowChart.getPlot();

LogarithmicAxis xAxis = new LogarithmicAxis("x");
LogarithmicAxis yAxis = new LogarithmicAxis("y");
xAxis.setLog10TickLabelsFlag(true);

plot.setDomainAxis(xAxis);
plot.setRangeAxis(yAxis);
plot.getRenderer().setSeriesVisibleInLegend(1, false);

LegendTitle chartLegend = flowChart.getLegend();
chartLegend.setPosition(RectangleEdge.TOP);

final ChartPanel chartPanel = new ChartPanel(flowChart);
chartPanel.setPreferredSize(new java.awt.Dimension(650, 300));
setContentPane(chartPanel);

}
public static void main(final String[] args)
{

final Stuff demo = new Stuff("Line Chart Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}
}
topher
 
Posts: 1
Joined: Fri Jan 08, 2016 3:27 am

Return to JFreeChart

Who is online

Users browsing this forum: Bing [Bot], david.gilbert, Google [Bot], Yahoo [Bot] and 7 guests