I am using XYStepChart from jFreeChart, couldn't able to get output graph for x-axis in numberical, instead i am getting in time format?
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();
}
}
Please help
XYStepChart from chart factory usage query
-
- Posts: 6
- Joined: Tue Feb 21, 2017 5:45 pm
- antibot: No, of course not.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: XYStepChart from chart factory usage query
xyplot.setDomainAxis(new NumberAxis(xAxisLabel);
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: XYStepChart from chart factory usage query
Cross-posted here.
-
- Posts: 6
- Joined: Tue Feb 21, 2017 5:45 pm
- antibot: No, of course not.
Re: XYStepChart from chart factory usage query
Hi, thanks for reply.. can you please tell where to edit exactly in my code.. i am newbie to jfreechart
I am unable to get desired output while using the suggested solution.
I am unable to get desired output while using the suggested solution.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: XYStepChart from chart factory usage query
Right after the line:
...and of course change 'xyplot' to just 'plot'.
Code: Select all
final XYPlot plot = chart.getXYPlot();
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 6
- Joined: Tue Feb 21, 2017 5:45 pm
- antibot: No, of course not.
Re: XYStepChart from chart factory usage query
Thank you very much .. able to generate now 
