[测评系统]--测评系统核心代码库
wzp
2025-08-01 95eb8a2a75cbeebcb3393d404c1952bd59b8989a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package com.ots.project.tool;
import com.ots.common.enums.LangTypeEnum;
import com.ots.framework.config.EssConfig;
import com.ots.project.exam.domain.TLibraryCode;
import com.ots.project.tool.report.MAQ.base.BaseCondition;
import lombok.extern.slf4j.Slf4j;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.springframework.stereotype.Component;
import java.awt.*;
import java.io.FileOutputStream;
import java.util.Map;
import java.util.UUID;
 
@Component
@Slf4j
public class BarChart extends BaseCondition {
    String percentile_score = "Percentile Score";
    String rowKey1 = "Task/Results Orientation";
    String rowKey2 = "People Orientation";
    JFreeChart chart;
    private BarChart() {
    }
    
    public String generateHistogram(Map<String, String> map, LangTypeEnum langTypeEnum) {
        TLibraryCode library1 = getMaqReportLibrary(map, "LIBMAQ31003", langTypeEnum);
        TLibraryCode library2 = getMaqReportLibrary(map, "LIBMAQ31005", langTypeEnum);
        TLibraryCode library3 = getMaqReportLibrary(map, "LIBMAQ32005", langTypeEnum);
        percentile_score = library1.getLangTypeContext(langTypeEnum);
        rowKey1 = library2.getLangTypeContext(langTypeEnum);
        rowKey2 = library3.getLangTypeContext(langTypeEnum);
        DefaultCategoryDataset data = getDefaultCategoryDataset(map);
        chart = getjFreeChart(data);
        FileOutputStream fos_jpg = null;
        String CHART_PATH = EssConfig.getUploadPath();
        String chartName = CHART_PATH + "/" + UUID.randomUUID() + ".png";
        try {
            fos_jpg = new FileOutputStream(chartName);
            ChartUtils.writeChartAsPNG(fos_jpg, chart, 1000, 200, true, 10);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fos_jpg.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return chartName;
    }
    private JFreeChart getjFreeChart(DefaultCategoryDataset data) {
        JFreeChart chart = ChartFactory.createBarChart(
                "",  
                "",
                percentile_score,
                data,
                PlotOrientation.HORIZONTAL,  
                false,  
                false,
                false);  
        
        
        CategoryPlot plot = chart.getCategoryPlot();
        
 
        
        CategoryAxis domain = plot.getDomainAxis();
        
        domain.setTickLabelFont(new Font("黑体", Font.BOLD, 16));
        
        domain.setLabelFont(new Font("黑体", Font.BOLD, 20));
        
        ValueAxis rangeAxis = plot.getRangeAxis();
        rangeAxis.setLabelFont(new Font("黑体", Font.BOLD, 16));
        
 
        chart.getTitle().setFont(new Font("黑体", Font.BOLD, 16));
        BarRenderer renderer = new BarRenderer();
 
 
 
 
        
        renderer.setDefaultOutlinePaint(Color.BLACK);
        
        renderer.setDrawBarOutline(true);
        
        renderer.setSeriesPaint(0, new Color(132, 140, 221));
        renderer.setSeriesPaint(1, new Color(45, 193, 112));
        
        renderer.setItemMargin(0.0);
        
        renderer.setIncludeBaseInRange(true);
        renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        renderer.setDefaultItemLabelsVisible(true);
        plot.setRenderer(renderer);
        
        plot.setForegroundAlpha(1.0f);
        return chart;
    }
    private DefaultCategoryDataset getDefaultCategoryDataset(Map<String, String> map) {
        int taskResultsOrientation;
        int peopleOrientation;
        try {
            taskResultsOrientation = Integer.valueOf(map.get("P_Task31"));
            peopleOrientation = Integer.valueOf(map.get("People32"));
        } catch (Exception ex) {
            taskResultsOrientation = 0;
            peopleOrientation = 0;
            log.error("柱状图参数为空,{}" + ex.getMessage(), ex);
        }
        return (DefaultCategoryDataset) getDataSet(taskResultsOrientation, peopleOrientation);
    }
    
    public CategoryDataset getDataSet(int taskResultsOrientation, int peopleOrientation) {
        DefaultCategoryDataset data = new DefaultCategoryDataset();
        
        data.setValue(0, rowKey1, rowKey1);
        data.setValue(taskResultsOrientation, rowKey2, rowKey1);
        data.setValue(peopleOrientation, rowKey1, rowKey2);
        data.setValue(0, rowKey2, rowKey2);
        return data;
    }
    @Override
    public String getName() {
        return null;
    }
    @Override
    public TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType) {
        return null;
    }
    @Override
    public Map<String, String> getMAQwaterDropsImages() {
        return null;
    }
}