Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add annotation in jfree line chart
    primarykey
    data
    text
    <p>Im using jfree charts for my application. I need a chart with stroke point values appear above the x axis label. </p> <p><strong>Expected</strong></p> <p><img src="https://i.stack.imgur.com/U1rsM.png" alt="enter image description here"></p> <p>And i need to remove the tick mark in between the values(54% and 2008). I have tried the below code to get the annotation,</p> <pre><code>final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(23, "Line", "2008"); dataset.addValue(145, "Line", "2009"); dataset.addValue(245, "Line", "2010"); dataset.addValue(322, "Line", "2011"); 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); chart.setBorderVisible(true); chart.setBorderPaint(Color.decode("#EEEEEE")); chart.setPadding(new RectangleInsets(10, 10, 5, 5)); 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.setTickLabelFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 8)); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); rangeAxis.setLabelPaint(Color.BLUE); rangeAxis.setRangeWithMargins(21, 600); DecimalFormat format = new DecimalFormat("###,###"); StandardCategoryItemLabelGenerator labelGenerator = new StandardCategoryItemLabelGenerator("{2}", format); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setSeriesStroke(0, new BasicStroke(1.5f)); renderer.setSeriesItemLabelsVisible(0, true); renderer.setBaseItemLabelGenerator(labelGenerator); renderer.setBaseItemLabelFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 9)); Shape circle = new Ellipse2D.Double(-2, -2, 4, 4); renderer.setSeriesShape(0, circle); plot.getRenderer().setSeriesPaint(0, Color.decode("#0066CC")); // CategoryAnnotation categoryAnnotation=new CategoryLineAnnotation(Male1, 248, Male2, 216, null, null); // XYLineAnnotation annotation=new XYLineAnnotation(8, 0, 8, 24, new BasicStroke(2.0f), Color.blue); // plot.addAnnotation( (CategoryAnnotation) annotation); try { ChartUtilities.saveChartAsPNG(new File("E:\\jfreeLinechart.png"), chart, 290, 95); System.out.println("=====chart====="); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>from the above code im getting the following chart</p> <p><strong>Actual</strong></p> <p><img src="https://i.stack.imgur.com/Gs5SP.png" alt="enter image description here"></p> <p>Please help me to get the expected image in jfree line chart.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload