挣值分析

没有具体计算

import javax.swing.*;
import java.awt.*;

public class EarnValueAnalysis extends JPanel {
    private double[] EV = {9, 31, 47.5};
    private double[] PV = {10, 35, 50};
    private double[] AC = {10, 36, 54};

    public EarnValueAnalysis() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);
        frame.getContentPane().add(this);
        frame.setVisible(true);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        int margin = 30;
        int width = getWidth();
        int height = getHeight();

        int[] xPoints = {50, 150, 250};
        int[] yPointsEV = {200 - (int) (EV[0] * 2), 200 - (int) (EV[1] * 2), 200 - (int) (EV[2] * 2)};
        int[] yPointsPV = {200 - (int) (PV[0] * 2), 200 - (int) (PV[1] * 2), 200 - (int) (PV[2] * 2)};
        int[] yPointsAC = {200 - (int) (AC[0] * 2), 200 - (int) (AC[1] * 2), 200 - (int) (AC[2] * 2)};

        g2d.setColor(Color.BLACK);

        // 绘制 x 轴
        g2d.drawLine(margin, height - margin, width - margin, height - margin);
        // 绘制 y 轴
        g2d.drawLine(margin, margin, margin, height - margin);

        // 绘制 x 轴标签
        g2d.drawString("时间(周)", width - margin - 10, height - margin + 20);
        // 绘制 y 轴标签
        g2d.drawString("钱(元)", margin - 20, margin - 10);

        // 绘制 x 轴刻度
        g2d.drawString("1", margin + 45, height - margin + 15);
        g2d.drawString("2", margin + 145, height - margin + 15);
        g2d.drawString("3", margin + 245, height - margin + 15);

        // 绘制 y 轴刻度
        g2d.drawString("10", margin - 20, height - margin - 20);
        g2d.drawString("20", margin - 20, height - margin - 80);
        g2d.drawString("30", margin - 20, height - margin - 140);
        g2d.drawString("40", margin - 20, height - margin - 200);
        g2d.drawString("50", margin - 20, height - margin - 260);
        g2d.drawString("60", margin - 20, height - margin - 320);

        g2d.setColor(Color.RED);
        g2d.setStroke(new BasicStroke(2));
        g2d.drawPolyline(xPoints, yPointsEV, 3);

        g2d.setColor(Color.GREEN);
        g2d.setStroke(new BasicStroke(2));
        g2d.drawPolyline(xPoints, yPointsPV, 3);

        g2d.setColor(Color.BLUE);
        g2d.setStroke(new BasicStroke(2));
        g2d.drawPolyline(xPoints, yPointsAC, 3);

        // 绘制左上角的线条含义说明
        g2d.setColor(Color.BLACK);
        g2d.drawString("EV - 红色", margin + 10, margin + 30);
        g2d.drawString("PV - 绿色", margin + 10, margin + 45);
        g2d.drawString("AC - 蓝色", margin + 10, margin + 60);

        g2d.setColor(Color.BLACK);
        g2d.setFont(new Font("宋体", Font.BOLD, 12));
        g2d.drawString("", xPoints[0], yPointsEV[0]);
        g2d.drawString("", xPoints[0], yPointsPV[0]);
        g2d.drawString("", xPoints[0], yPointsAC[0]);

        g2d.drawString("净值分析", width / 2 - 40, height - margin + 40);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(EarnValueAnalysis::new);
    }
}

 

posted @ 2024-04-08 18:45  风·华正茂  阅读(15)  评论(0编辑  收藏  举报