我有一个运行正常的程序,它使用不同的自变量值重复一系列公式。我现在想要在循环的每次迭代之后绘制计算图。这就是我到目前为止所做的:
public static void main(String[] args) {
JFrame window=new JFrame();
window.setTitle("Try");
window.setSize(600, 400);
window.setLayout(new BorderLayout());
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
XYSeries series = new XYSeries("graph");
XYSeriesCollection dataset= new XYSeriesCollection(series);
...
我的重要问题是如何获取数据并生成数据集,然后如何在循环的每次迭代后更新图形?我已经导入了JFreeChart类和一些swing。任何和所有的见解将不胜感激。
答案 0 :(得分:0)
所以我在一段时间后想出来了。诀窍是在循环内部设置可见。但现在,JFrame会在每次迭代时重绘。我不知道是否有办法保持帧不变。如果有人知道,我将不胜感激。
package trylog{
import javax.swing.JFrame;
import java.awt.BorderLayout;
java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.data.general.DatasetChangeListener;
import org.jfree.data.general.DatasetGroup;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import sun.security.jca.GetInstance.Instance;
public class TryLog {
private static Object InstanceTools;
public static void main(String[] args) {
JFrame window=new JFrame();
window.setTitle("Try");
window.setSize(600, 400);
window.setLayout(new BorderLayout());
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//window.setVisible(true);
XYSeries series = new XYSeries("graph");
XYSeriesCollection dataset= new XYSeriesCollection(series);
double[] newArray= new double[1000];
for (int j=0;j<1000;j++)
{
newArray[j]=1+10;
}
JFreeChart chart=ChartFactory.createXYLineChart("Graph Try", "hi", "bye", dataset);
window.add(new ChartPanel(chart),BorderLayout.CENTER);
int x=0;
int number=10;
JFrame window1=new JFrame();
window1.setTitle("Try");
window1.setSize(600, 400);
window1.setLayout(new BorderLayout());
window1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//window.setVisible(true);
XYSeries series1 = new XYSeries("graph");
XYSeriesCollection dataset1= new XYSeriesCollection(series1);
double[] newArray1= new double[1000];
for (int j=0;j<1000;j++)
{
newArray[j]=1+10;
}
JFreeChart chart1=ChartFactory.createXYLineChart("Graph Try", "hi", "bye", dataset1);
window1.add(new ChartPanel(chart1),BorderLayout.CENTER);
int y=0;
int number1=10;
for (int i=0;i<10000;i++)
{
series.add(x,number);
x++;
number++;
window.setVisible(true);
series1.add(y,number1);
y++;
number1++;
window1.setVisible(true);
}
}