Reputation:
Im using jfreecharts for my application. I need to remove the x-axis line in the Line chart produced. How can i remove the axis line, Any help would be appreciated.
Upvotes: 1
Views: 117
Reputation: 810
To remove your axis line and tick marks, refer this code.
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, "Line", "2009");
dataset.addValue(2.0, "Line", "2010");
dataset.addValue(null, "Line", "2011");
dataset.addValue(3.0, "Line", "2012");
final JFreeChart chart = ChartFactory.createLineChart(
"", // chart title
"", // domain axis label
"", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
false, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.WHITE);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setRangeZeroBaselinePaint(Color.RED);
plot.setOutlineVisible(false);
plot.setRangeGridlinePaint(Color.white);
plot.setDomainGridlinePaint(Color.BLUE);
final CategoryAxis categoryAxis = (CategoryAxis) plot.getDomainAxis();
categoryAxis.setAxisLineVisible(false);
categoryAxis.setTickMarksVisible(false);
//categoryAxis.setVisible(false);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
//rangeAxis.setAxisLineVisible(false);
rangeAxis.setVisible(false);
rangeAxis.setLabelPaint(Color.BLUE);
rangeAxis.setRange(0, 3);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
//renderer.setItemLabelsVisible(false); //Deprecated.
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
renderer.setSeriesStroke(0, new BasicStroke(2.0f));
Shape circle = new Ellipse2D.Double(-3, -3, 6, 6);
renderer.setSeriesShape(0, circle);
plot.getRenderer().setSeriesPaint(0, Color.BLUE);
try {
ChartUtilities.saveChartAsPNG(new File("E:\\jfreeLinechart.png"), chart, 211, 90);
System.out.println("=====chart=====");
} catch (Exception e) {
e.printStackTrace();
}
Also refer this link
Upvotes: 1