我想通过增加值来显示我的x轴

时间:2016-07-08 19:54:31

标签: java excel apache-poi

基本上我能够用我喜欢的格式绘制我想要的信息。我希望我的x轴以增量顺序显示其值,而不是按照它们被读取的顺序显示....与y轴的显示方式相同;按增量顺序。也许它默认显示这种方式,因为它是输出值,但我想对x轴是相同的....我已经看过AxisOrientation API并尝试搞乱它但没有...任何提示有助于。谢谢

 XSSFWorkbook my_workbook = new XSSFWorkbook(); 
 XSSFSheet my_worksheet = my_workbook.createSheet("example");
 XSSFRow row = my_worksheet.createRow(0);
   row.createCell(0).setCellValue(4);
   row.createCell(1).setCellValue(6);
   row = my_worksheet.createRow(1);
   row.createCell(0).setCellValue(2);
   row.createCell(1).setCellValue(10);
   row = my_worksheet.createRow(2);
   row.createCell(0).setCellValue(8);
   row.createCell(1).setCellValue(5);

   XSSFDrawing xlsx_drawing = my_worksheet.createDrawingPatriarch();
   XSSFClientAnchor anchor = xlsx_drawing.createAnchor(0, 0, 0, 0, 0, 10, 10, 20); 
   XSSFChart my_line_chart = xlsx_drawing.createChart(anchor);
   XSSFChartLegend legend = my_line_chart.getOrCreateLegend();
   legend.setPosition(LegendPosition.BOTTOM);
   LineChartData data = my_line_chart.getChartDataFactory().createLineChartData();

   ChartAxis bottomAxis = my_line_chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
      // bottomAxis.setOrientation(AxisOrientation.MIN_MAX);
    ValueAxis leftAxis = my_line_chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);

      ChartDataSource<Number> x = DataSources.fromNumericCellRange(my_worksheet, new CellRangeAddress(0, 2, 0, 0));
      ChartDataSource<Number> y = DataSources.fromNumericCellRange(my_worksheet, new CellRangeAddress(0, 2, 1, 1));
      data.addSeries(x, y);      
      my_line_chart.plot(data, new ChartAxis[] { bottomAxis, leftAxis });   

 // bottomAxis.setOrientation(AxisOrientation.MIN_MAX);

1 个答案:

答案 0 :(得分:0)

JFreeChart是创建图表的最佳方式..