Attached my code snippet here, I am using XYStepChart
from chart factory. The x-axis scale at output for the code is being displayed in scale of eg: 05:30:00:00
, 05:30:00:01
, 05:30:00:00
. But I need in values like 1,2,3,4.
package org.jfree.chart.demo;
import java.awt.BasicStroke;
import java.awt.Color;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RefineryUtilities;
public class XYStepChartDemo
{
private ChartFrame frame = null;
private void displayChart() {
if (this.frame == null) {
final String title = "Trace";
final String xAxisLabel = "Tasks";
final String yAxisLabel = "Amplitude";
final XYDataset data = createStepXYDataset();
final JFreeChart chart = ChartFactory.createXYStepChart(
title,
xAxisLabel, yAxisLabel,
data,
PlotOrientation.VERTICAL,
true, // legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(new Color(216, 216, 216));
final XYPlot plot = chart.getXYPlot();
plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
this.frame = new ChartFrame("Plan Comparison", chart);
this.frame.pack();
RefineryUtilities.positionFrameRandomly(this.frame);
this.frame.setVisible(true);
}
else {
this.frame.setVisible(true);
this.frame.requestFocus();
}
}
public static XYDataset createStepXYDataset() {
final XYSeries series1 = new XYSeries("Series 2");
series1.add(0, 5);
series1.add(1, 0);
series1.add(2, 0);
series1.add(3, 0);
series1.add(4, 0);
series1.add(5, 5);
series1.add(6, 0);
series1.add(7, 0);
series1.add(8, 0);
final XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
return dataset;
}
public static void main(final String[] args) {
final XYStepChartDemo demo = new XYStepChartDemo();
demo.displayChart();
}
}