I'm using a JFreeChart which I found in this link http://www.java2s.com/Code/Java/Chart/JFreeChartCategoryStepChartDemo.htm
I have modified the code as given below.My problem is how i can change the values in the x-axis so that they don't start from the zero.
public class Chart1 extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Creates a new demo application.
*
* @param title the frame title.
* @throws SQLException
*/
public Chart1(DefaultTableModel model,final double [][] data) throws SQLException {
super();
final CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
"Country ", "year ", data
);
// create the chart...
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
chartPanel.setEnforceFileExtensions(false);
this.add(chartPanel);
}
/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(final CategoryDataset dataset) {
final CategoryItemRenderer renderer = new CategoryStepRenderer(true);
final CategoryAxis domainAxis = new CategoryAxis("Category");
final ValueAxis rangeAxis = new NumberAxis("jiji");
final CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
final JFreeChart chart = new JFreeChart("Category Step Chart", plot);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// set the background color for the chart...
// final StandardLegend legend = (StandardLegend) chart.getLegend();
// legend.setAnchor(StandardLegend.SOUTH);
chart.setBackgroundPaint(Color.white);
// plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
plot.setBackgroundPaint(Color.yellow);
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.white);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
// OPTIONAL CUSTOMISATION COMPLETED.
return chart;
}