XYStepChart from chart factory usage query

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
praneethshub
Posts: 6
Joined: Tue Feb 21, 2017 5:45 pm
antibot: No, of course not.

XYStepChart from chart factory usage query

Post by praneethshub » Tue Feb 21, 2017 5:59 pm

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

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: XYStepChart from chart factory usage query

Post by paradoxoff » Tue Feb 21, 2017 9:46 pm

xyplot.setDomainAxis(new NumberAxis(xAxisLabel);

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: XYStepChart from chart factory usage query

Post by John Matthews » Tue Feb 21, 2017 11:41 pm

Cross-posted here.

praneethshub
Posts: 6
Joined: Tue Feb 21, 2017 5:45 pm
antibot: No, of course not.

Re: XYStepChart from chart factory usage query

Post by praneethshub » Wed Feb 22, 2017 2:21 am

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.

david.gilbert
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

Post by david.gilbert » Wed Feb 22, 2017 9:16 am

Right after the line:

Code: Select all

final XYPlot plot = chart.getXYPlot();
...and of course change 'xyplot' to just 'plot'.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

praneethshub
Posts: 6
Joined: Tue Feb 21, 2017 5:45 pm
antibot: No, of course not.

Re: XYStepChart from chart factory usage query

Post by praneethshub » Wed Feb 22, 2017 2:21 pm

Thank you very much .. able to generate now :)

Locked