私は最初のクラスを持っています
public class GetResults{
public double[] tableOfresults() {
double[] outputArray = new double[100];
double time;
double results
for(time = 0; time<outputArray.length; i++) {
//Some values are calculated and then stored in an array as below
outputArray[(int)Time] = Results
}
return outputarray;
このクラスは、グラフにプロットしたいいくつかの値を計算し、それらを配列に格納するだけです。
この次のクラスは、実際にグラフにポイントをプロットするものです。時間の値 (時間は配列インデックス 0,1,2,3 ect) である X 軸と結果である Y 軸にプロットするポイントを取得する簡単な方法がわかりません。私は現在、すべてのポジションを自分で配置する必要があります。
public class graph{
GetResults gr = new GetResuts();
public XYSeries inputOutputGraph() {
XYSeries graph = new XYSeries("My graph");
XYDataset xyDataset = new XYSeriesCollection(graph);
graph.add(1, gr.tableOfResults()[1]);
graph.add(2, gr.tableOfResults()[2]);
graph.add(3, gr.tableOfResults()[3]);
graph.add(4, gr.tableOfResults()[4]);
ここでは、自分で値を追加する必要があります (1000 を行う必要があります)。次のようなものが必要です graph.add(gr.tableOfResults()[gr.Time], gr.tableOfResults()[gr.Results]); そのため、時間が 0,1,2,3 上がると、その位置のインデックス 0,1,2,3 に格納されている結果がプロットされます。どうすればこれを行うことができますか?? 私はそのコードを試しました^^そして、配列サイズが設定された値で範囲外の配列インデックスを取得しました
JFreeChart chart = ChartFactory.createXYLineChart(
"Graph", "Time", "results",
xyDataset, PlotOrientation.VERTICAL, true, true, false);
ChartFrame graphFrame = new ChartFrame("XYLine Chart", chart);
graphFrame.setVisible(true);
graphFrame.setSize(300, 300);
return graph;
}
}