|
@@ -30,16 +30,11 @@ import org.jfree.chart.ChartFactory;
|
|
|
import org.jfree.chart.ChartPanel;
|
|
|
import org.jfree.chart.ChartUtils;
|
|
|
import org.jfree.chart.JFreeChart;
|
|
|
-import org.jfree.chart.axis.CategoryAxis;
|
|
|
-import org.jfree.chart.axis.NumberAxis;
|
|
|
-import org.jfree.chart.axis.NumberTickUnit;
|
|
|
-import org.jfree.chart.axis.ValueAxis;
|
|
|
-import org.jfree.chart.plot.CategoryPlot;
|
|
|
-import org.jfree.chart.plot.PlotOrientation;
|
|
|
-import org.jfree.chart.plot.ValueMarker;
|
|
|
-import org.jfree.chart.plot.XYPlot;
|
|
|
+import org.jfree.chart.axis.*;
|
|
|
+import org.jfree.chart.plot.*;
|
|
|
import org.jfree.chart.renderer.category.BarRenderer;
|
|
|
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
|
|
|
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
|
|
import org.jfree.chart.renderer.xy.XYSplineRenderer;
|
|
|
import org.jfree.chart.title.TextTitle;
|
|
|
import org.jfree.data.category.CategoryDataset;
|
|
@@ -1253,6 +1248,8 @@ public class FormulaUtils {
|
|
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
BufferedImage bufferedImage = chart.createBufferedImage(800, 600);
|
|
|
ImageIO.write(bufferedImage, "png", out);
|
|
|
+ FileOutputStream fos = new FileOutputStream("C:/Users/yangyj/Desktop/Swap_space/poi_statistics.png");
|
|
|
+ fos.write(out.toByteArray());
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -1277,8 +1274,7 @@ public class FormulaUtils {
|
|
|
CategoryDataset dataset = createDataset(actualProgress,plannedProgress);
|
|
|
JFreeChart chart = createChart(dataset);
|
|
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
- BufferedImage bufferedImage = chart.createBufferedImage(800, 600);
|
|
|
- ImageIO.write(bufferedImage, "png", out);
|
|
|
+ ChartUtils.writeChartAsPNG(out, chart, 800, 600);
|
|
|
return out.toByteArray();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -1286,10 +1282,11 @@ public class FormulaUtils {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public static String chapterScheduleChartUrl( double[] actualProgress ,double[] plannedProgress){
|
|
|
- CategoryDataset dataset = createDataset(actualProgress,plannedProgress);
|
|
|
- JFreeChart chart = createChart(dataset);
|
|
|
+ public static String chapterScheduleChartUrl( double[] actual ,double[] planned){
|
|
|
+ /*CategoryDataset dataset = createDataset(actualProgress,plannedProgress);
|
|
|
+ JFreeChart chart = createChart(dataset);*/
|
|
|
try {
|
|
|
+ JFreeChart chart =chartTest(actual,planned);
|
|
|
String path= getSysLocalFileUrl() + "/pdf//"+SnowFlakeUtil.getId()+".png";
|
|
|
ChartUtils.saveChartAsPNG(new File(path), chart, 800, 600);
|
|
|
return path;
|
|
@@ -1300,6 +1297,85 @@ public class FormulaUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static JFreeChart chartTest(double[] actualProgressData ,double[] plannedProgressData) throws IOException {
|
|
|
+ // 创建数据集
|
|
|
+ XYSeries actualProgress = new XYSeries("实际进度");
|
|
|
+ XYSeries plannedProgress = new XYSeries("计划进度");
|
|
|
+
|
|
|
+ /* // 数据
|
|
|
+ double[][] actualProgressData = {{1, 10}, {2, 15}, {3, 18}, {4, 27}, {5, 35}, {6, 48}};
|
|
|
+ double[][] plannedProgressData = {{1, 10}, {2, 15}, {3, 20}, {4, 25}, {5, 30}, {6, 35}};*/
|
|
|
+
|
|
|
+ // 填充数据集
|
|
|
+ for (int i = 0; i < actualProgressData.length; i++) {
|
|
|
+ actualProgress.add(i, actualProgressData[i]);
|
|
|
+ plannedProgress.add(i, plannedProgressData[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ XYSeriesCollection dataset = new XYSeriesCollection();
|
|
|
+ dataset.addSeries(actualProgress);
|
|
|
+ dataset.addSeries(plannedProgress);
|
|
|
+
|
|
|
+ // 创建图表
|
|
|
+ JFreeChart chart = ChartFactory.createXYLineChart(
|
|
|
+ "施工进度对比图", // 标题
|
|
|
+ "日期进度 (%)", // X轴标签
|
|
|
+ "完成量 (%)", // Y轴标签
|
|
|
+ dataset, // 数据集
|
|
|
+ org.jfree.chart.plot.PlotOrientation.VERTICAL, // 方向
|
|
|
+ true, // 显示图例
|
|
|
+ true, // 生成工具
|
|
|
+ false // 生成URL
|
|
|
+ );
|
|
|
+
|
|
|
+ // 设置中文字体以避免乱码
|
|
|
+ Font font = new Font("宋体", Font.PLAIN, 12);
|
|
|
+ chart.getTitle().setFont(font);
|
|
|
+ chart.getLegend().setItemFont(font);
|
|
|
+
|
|
|
+ XYPlot plot = chart.getXYPlot();
|
|
|
+ plot.setDomainGridlinesVisible(true);
|
|
|
+ plot.setRangeGridlinesVisible(true);
|
|
|
+ plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
|
|
|
+ plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
|
|
|
+ plot.setBackgroundPaint(Color.WHITE);
|
|
|
+
|
|
|
+ XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
|
|
|
+ renderer.setSeriesPaint(0, Color.BLUE);
|
|
|
+ renderer.setSeriesPaint(1, Color.GREEN);
|
|
|
+ plot.setRenderer(renderer);
|
|
|
+
|
|
|
+/* // 设置主X轴
|
|
|
+ NumberAxis domainAxis = new NumberAxis("日期进度 (%)");
|
|
|
+ domainAxis.setRange(0, 100);
|
|
|
+ domainAxis.setTickUnit(new NumberTickUnit(10));
|
|
|
+ domainAxis.setTickLabelFont(font);
|
|
|
+ domainAxis.setLabelFont(font);*/
|
|
|
+
|
|
|
+
|
|
|
+ // 设置顶部的月份轴
|
|
|
+ String[] months = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
|
|
|
+ SymbolAxis monthAxis = new SymbolAxis("月份", months);
|
|
|
+ monthAxis.setTickLabelFont(font);
|
|
|
+ monthAxis.setLabelFont(font);
|
|
|
+ monthAxis.setRange(0, 11); // 设置范围来适应月份标签
|
|
|
+ plot.setDomainAxis(monthAxis);
|
|
|
+
|
|
|
+ // 设置Y轴的范围
|
|
|
+ NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
|
|
|
+ rangeAxis.setRange(0, 100); // Y轴从0到100
|
|
|
+ rangeAxis.setTickUnit(new NumberTickUnit(10));
|
|
|
+ rangeAxis.setLabelFont(font);
|
|
|
+ rangeAxis.setTickLabelFont(font);
|
|
|
+
|
|
|
+ /* // 添加月份轴
|
|
|
+ plot.setRangeAxis(2, monthAxis);
|
|
|
+ plot.mapDatasetToDomainAxis(0, 1); // 将数据映射到月份轴*/
|
|
|
+
|
|
|
+ return chart;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**字符串sha256映射*/
|
|
|
public static String sha256(String input) {
|
|
|
try {
|