gpt4 book ai didi

java - 从 JFreeChart 获取多个数据集

转载 作者:行者123 更新时间:2023-12-02 05:42:40 25 4
gpt4 key购买 nike

我使用 JFreeChart 在同一个图表上有 2 个数据集。我试图对图表上的点的相似程度进行比较,因此我需要访问之前放入图表中的 2 个数据集,但由于某种原因,我似乎无法提取此信息。

以下是数据的输入方式:

 private static IntervalXYDataset createDataset()
{
DefaultXYDataset completeDataset = new DefaultXYDataset();

//populate with simulated data
double[][] sim = new double[2][simData.size()];
for(int i = 0; i < simData.size(); i++){
sim[0][i] = simData.get(i).getOne();
sim[1][i] = simData.get(i).getTwo();
}

//populated with known experimental data
double[][] exp = new double[2][expData.size()];
for(int i = 0; i < expData.size(); i++){
exp[0][i] = expData.get(i).getOne();
exp[1][i] = expData.get(i).getTwo();
}

completeDataset.addSeries("Simulated", sim);
completeDataset.addSeries("Experimental", exp);

XYBarDataset dataset = new XYBarDataset(completeDataset, .1);

return dataset;
}

数据最初是作为一对存储的,但我知道数据是按照图形正确显示的那样输入的。如何返回此数据集中的两个系列?

最佳答案

如果我理解正确的话,您想从completeDataset 中检索您的2 个数据集?

由于 DefaultXYDataset 有一些限制,您可以尝试类似的方法作为解决方法。我还没有测试过它,所以可能需要一些调整:)

    completeDataset .addSeries("Simulated", sim); //"Simulated" will be at position 0
completeDataset .addSeries("Experimental", exp); //"Experimental" will be at position 1

//get series length
int countSeries1 = completeDataset.getItemCount(0); //number of items in Simulated
int countSeries2 = completeDataset.getItemCount(1); //number of items in Experimental

double[][] series1 = new double[2][countSeries1];
double[][] series2 = new double[2][countSeries2];

//recreate Simulated series
for(int i = 0; i < countSeries1; i++){

series1[0][i] = completeDataset.getXValue(0, i);
series1[1][i] = completeDataset.getYValue(0, i);

}
//recreate Experimental series
for(int i = 0; i < countSeries2; i++){

series2[0][i] = completeDataset.getXValue(1, i);
series2[1][i] = completeDataset.getYValue(1, i);

}

关于java - 从 JFreeChart 获取多个数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24380752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com