FastScatterPlot でデータが表示されない FastScatterPlot (JFreeChart) でポイント サイズまたは形状を変更するにはどうすればよいですか?
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:
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.
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2452
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权