原创

FastScatterPlot 不显示数据 如何更改 FastScatterPlot (JFreeChart) 中的点大小或形状?

温馨提示:
本文最后更新于 2024年04月12日,已超过 37 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

I am trying to build a charting application as a project for college, using JFreeChart to build the graphs and Swing to build the UI. After some debugging Im at a point where the file parser is reading the data correctly, the chart is being built and the panel containing the chart is being displayed to the user. But the chart does not contain the data. Here is the code that builds my scatter plot:

import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.FastScatterPlot;


public class ScatterPlot extends Chart{

    

    public ScatterPlot(String title, float[][] data) {
            
        this.data = data;
        //CSVParser.printArrayToConsole(this.data[1]);
        NumberAxis domainAxis = new NumberAxis("X");
        domainAxis.setAutoRangeIncludesZero(false);
        NumberAxis rangeAxis = new NumberAxis("Y");
        rangeAxis.setAutoRangeIncludesZero(true);
        FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
        JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
        ChartUtils.applyCurrentTheme(chart);

        panel = new ChartPanel(chart);
        panel.setPreferredSize(new java.awt.Dimension(500, 270));
        panel.setMinimumDrawHeight(10);
        panel.setMaximumDrawHeight(2000);
        panel.setMinimumDrawWidth(20);
        panel.setMaximumDrawWidth(2000);

    }
}

Here is the Chart class from which that inherits:

import org.jfree.chart.ChartPanel;
import javax.swing.JPanel;
import org.jfree.chart.plot.FastScatterPlot;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.JFreeChart;


public class Chart {
    
    float[][] data;
    ChartPanel panel;
    
    public Chart(){
        initChartPanel();
    }
    
    private void initChartPanel(){
        float[][] tempData = {{0}, {0}};
        FastScatterPlot plot = new FastScatterPlot(tempData, new NumberAxis(""), new NumberAxis(""));
        JFreeChart chart = new JFreeChart("If you're seeing this, something went wrong.", plot);
        panel = new ChartPanel(chart);
    }
    
}

Here is the dataset i used for this output (read from a CSV file):

0,1,2,3,4,5,6,7,8,9,10,11
4.2,4,3.7,3.4,3.2,2.9,2.6,2.4,2.1,1.8,1.5,1.2

Here is the output of running this code:

Scatter plot with no data

I have tried:

  • setting the range manually
  • disabling setAutoRange
  • adding the ability to zoom to see if the points were too small to be seen (nope)
  • resizing the points using an extension of the FastScatterPlot class that someone else wrote

As a sidenote, the ScatterPlot class was written by a teammate of mine and im quite certain that he did not write it himself but instead just copy and pasted it from a tutorial. We agreed that Id build the UI and hed handle the chart-building side of things. I made a few modifications to fit into what I have, but this is to say Im not really familiar with JFreeChart and I believe neither is he so I cant ask him for help.

Any help is appreciated.

正文到此结束
热门推荐
本文目录