|
@@ -37,6 +37,7 @@ 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.chart.ui.RectangleEdge;
|
|
|
import org.jfree.data.category.CategoryDataset;
|
|
|
import org.jfree.data.category.DefaultCategoryDataset;
|
|
|
import org.jfree.data.xy.XYSeries;
|
|
@@ -67,6 +68,7 @@ import javax.imageio.ImageIO;
|
|
|
import java.awt.*;
|
|
|
import java.awt.Font;
|
|
|
import java.awt.Shape;
|
|
|
+import java.awt.geom.AffineTransform;
|
|
|
import java.awt.geom.Ellipse2D;
|
|
|
import java.awt.geom.Rectangle2D;
|
|
|
import java.awt.image.BufferedImage;
|
|
@@ -1247,27 +1249,6 @@ public class FormulaUtils {
|
|
|
return chart;
|
|
|
}
|
|
|
|
|
|
- public static void mainT2(String[] args) {
|
|
|
- double[] actualProgress = {10, 15, 18, 27, 35, 48};
|
|
|
- double[] plannedProgress = {10, 15, 20, 25, 30, 35};
|
|
|
- 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);
|
|
|
- FileOutputStream fos = new FileOutputStream("C:/Users/yangyj/Desktop/Swap_space/poi_statistics.png");
|
|
|
- fos.write(out.toByteArray());
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-/* try {
|
|
|
- ChartUtils.saveChartAsPNG(new File("C:/Users/yangyj/Desktop/Swap_space/poi_statistics.png"), chart, 800, 600);
|
|
|
- // 保存图表到内存
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
- }
|
|
|
|
|
|
public static String getSysLocalFileUrl() {
|
|
|
String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
@@ -1310,10 +1291,6 @@ public class FormulaUtils {
|
|
|
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]);
|
|
@@ -1362,11 +1339,21 @@ public class FormulaUtils {
|
|
|
|
|
|
|
|
|
// 设置顶部的月份轴
|
|
|
- String[] months = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
|
|
|
- SymbolAxis monthAxis = new SymbolAxis("月份", months);
|
|
|
+ /* String[] months = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
|
|
|
+ String[] years = {"2023年", "2024年", "2025年", "2026年"};*/
|
|
|
+ String[] months =new String[4 * 12];
|
|
|
+ for(int i=2023;i<=2026;i++){
|
|
|
+ for(int n=1;n<=12;n++){
|
|
|
+ int index=(i-2023)*12+n-1;
|
|
|
+ months[index]=i+"年"+n+"月";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 设置顶部的月份轴
|
|
|
+ SymbolAxis monthAxis = new SymbolAxis("月份", months) ;
|
|
|
monthAxis.setTickLabelFont(font);
|
|
|
monthAxis.setLabelFont(font);
|
|
|
- monthAxis.setRange(0, 11); // 设置范围来适应月份标签
|
|
|
+ monthAxis.setVerticalTickLabels(true);
|
|
|
+ monthAxis.setRange(0, 47); // 设置范围来适应月份标签
|
|
|
plot.setDomainAxis(monthAxis);
|
|
|
|
|
|
// 设置Y轴的范围
|
|
@@ -1382,6 +1369,84 @@ public class FormulaUtils {
|
|
|
|
|
|
return chart;
|
|
|
}
|
|
|
+ public static JFreeChart chartTest2(double[] actualProgressData, double[] plannedProgressData) {
|
|
|
+ // 创建数据集
|
|
|
+ DefaultCategoryDataset dataset = new DefaultCategoryDataset();
|
|
|
+ String[] months = new String[4 * 12];
|
|
|
+ for (int i = 2023; i <= 2026; i++) {
|
|
|
+ for (int n = 1; n <= 12; n++) {
|
|
|
+ int index = (i - 2023) * 12 + n - 1;
|
|
|
+ months[index] = i + "年" + n + "月";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < months.length; i++) {
|
|
|
+ dataset.addValue(actualProgressData.length-1>i?actualProgressData[i]:0, "实际进度", months[i]);
|
|
|
+ dataset.addValue(plannedProgressData.length-1>i?plannedProgressData[i]:0, "计划进度", months[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建图表
|
|
|
+ JFreeChart chart = ChartFactory.createLineChart(
|
|
|
+ "施工进度对比图", // 标题
|
|
|
+ "日期进度 (%)", // X轴标签
|
|
|
+ "完成量 (%)", // Y轴标签
|
|
|
+ dataset // 数据集
|
|
|
+ );
|
|
|
+
|
|
|
+ // 设置中文字体以避免乱码
|
|
|
+ Font font = new Font("宋体", Font.PLAIN, 12);
|
|
|
+ chart.getTitle().setFont(font);
|
|
|
+ chart.getLegend().setItemFont(font);
|
|
|
+
|
|
|
+ CategoryPlot plot = (CategoryPlot) chart.getPlot();
|
|
|
+ plot.setDomainGridlinesVisible(true);
|
|
|
+ plot.setRangeGridlinesVisible(true);
|
|
|
+ plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
|
|
|
+ plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
|
|
|
+ plot.setBackgroundPaint(Color.WHITE);
|
|
|
+
|
|
|
+ LineAndShapeRenderer renderer = new LineAndShapeRenderer();
|
|
|
+ renderer.setSeriesPaint(0, Color.BLUE);
|
|
|
+ renderer.setSeriesPaint(1, Color.GREEN);
|
|
|
+ plot.setRenderer(renderer);
|
|
|
+
|
|
|
+ // 设置顶部的月份轴
|
|
|
+ CategoryAxis monthAxis = new CategoryAxis("月份");
|
|
|
+ monthAxis.setTickLabelFont(font);
|
|
|
+ monthAxis.setLabelFont(font);
|
|
|
+ monthAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 设置标签倾斜45度
|
|
|
+ monthAxis.setMaximumCategoryLabelWidthRatio(1.0f); // 确保所有标签显示
|
|
|
+ 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);
|
|
|
+
|
|
|
+ return chart;
|
|
|
+ }
|
|
|
+ public static void main(String[] args) throws IOException {
|
|
|
+ double[] actualProgress = {10, 15, 18, 27, 35, 48};
|
|
|
+ double[] plannedProgress = {10, 15, 20, 25, 30, 35};
|
|
|
+
|
|
|
+ JFreeChart chart = chartTest2(actualProgress,plannedProgress);
|
|
|
+/* 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();
|
|
|
+ }*/
|
|
|
+ try {
|
|
|
+ ChartUtils.saveChartAsPNG(new File("C:/Users/yangyj/Desktop/Swap_space/poi_statistics.png"), chart, 800, 600);
|
|
|
+ // 保存图表到内存
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**字符串sha256映射*/
|