JFreeChart的一个方便的接口

本文介绍如何利用JFreeChart库在Java中创建图表,通过简洁的接口实现数据可视化,便于理解和操作。
摘要由CSDN通过智能技术生成
JFreeChart是一个强大的库,但其使用较为复杂,本文定义了一套方便的接口,可类似于XChart一样,方便使用。使用JFreeChart时,需导入JFreeChart 1.5.4版本的包。效果如下:

代码如下:

import com.formdev.flatlaf.FlatLightLaf;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.chart.ui.*;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.util.ArrayList;

public class Plot {
    private JFreeChart chart;
    private final ArrayList<Line> lines = new ArrayList<>();

    private Font axisLabelFont = new Font("Microsoft YaHei", Font.PLAIN, 11);
       //     new Font("Microsoft YaHei", Font.PLAIN, 11);
    private String titleText = "";
    private String xAxisTitle = "x";
    private String yAxisTitle = "y";
    private boolean verticalGridLineVisible = true;
    private boolean horizontalGridLineVisible = true;

    private double xmin = 0;
    private double xmax = 0;
    private double ymin = 0;
    private double ymax = 0;

    class Line {
        double[] x;
        double[] y;
        Color color = Color.BLACK;
        BasicStroke stroke = new BasicStroke(1.5f);
        boolean showMarker = false;
        int markerSize = 4;
        boolean lineVisible = true;
        boolean itemLabelsVisible = false;
        char markerType = 'c';
        boolean markerFilled = false;
        boolean isVerticalLine = false;
        String verticalLineLabel = "";
        boolean isLabel = false;
        String label = "";
        float labelAngle = 0;
    }


    public Plot verticalGridLineVisible(boolean bool) {
        this.verticalGridLineVisible = bool;
        System.out.println("执行");
        return this;
    }

    public Plot horizontalGridLineVisible(boolean bool) {
        this.horizontalGridLineVisible = bool;
        return this;
    }


    public Plot line(double[] x, double[] y,
                    Color color, float lineWidth, boolean lineVisible,
                    boolean dashed, Character markerType, boolean showMarker,
                    int markerSize, boolean itemLabelVisible) {

        Line line = new Line();
        line.x = x;
        line.y = y;
        line.color = color;
        line.showMarker = showMarker;
        line.markerSize = markerSize;
        line.lineVi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值