내 응용 프로그램에 jfree 차트를 사용하고 있습니다. 스트로크 포인트 값이 x 축 레이블 위에 표시되는 차트가 필요합니다.jfree 꺾은 선형 차트에 주석을 추가하는 방법
예상
와 나는 값 (54 % 및 2008) 사이에 눈금 표시를 제거해야합니다. 내가 주석을 얻기 위해 아래의 코드를 시도 ,
실제 다음 표를 얻기 위의 코드 메신저에서
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();
}
것은
를 얻기 위해 제발 도와주세요 예상 이미지 jfree 꺾은 선형 차트.
좋은 해결책이 생겼습니다 !!. 화이트 색상을 사용하거나 jfreechart를 사용하여 시리즈를 숨기거나 표시하는 등의 일을하는 것이 일반적입니다. –