使用 JfreeChart 动态向 XYSeries 添加点
我在向 XYSeries 添加点时遇到问题。我有两节课。一个是 Sample
(它有一个 main
方法),另一个类是 JfreeChart
(它有 JfreeChart
代码) 。在我的 Sample
类中,我有一个 2D 数组 sample[row][2]
,最初有 10 行,然后我需要调用 JfreeChart
> 类并将它们添加到 XYSeries 并显示散点图。我设法做到了这一点,但下次调用 Jfreechart 类时,我的数组有 25 行。
我需要将值添加到 XYSeries 并将它们绘制在散点图上,该散点图应该显示之前 10 行不同颜色的值,现在 25 行不同颜色的值……这样继续下去。谁能给出一些建议或例子?
class Sample {
public static void main(String args[]) {
System.out.print("(X,Y) Paired Values");
double[][] sample = new double[row][2];
for (int g = 0; g < sampe.length; g++) {
for (int h = 0; h < 2; h++) {
System.out.print("" + sample[g][h] + ",");
}
}
JfreeChart sample = new JfreeChart("Demo", sample);
}
static XYDataset samplexydataset2(double[][] sample) {
XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
XYSeries series = new XYSeries("DataSet");
for (int x = 0; x < sample.length; x++) {
series.add(sample[x][0], sample[x][1]);
}
xySeriesCollection.addSeries(series);
return xySeriesCollection;
}
}
1)当我调用“第一次”JfreeChart 类时,我的示例数组中将包含这些对
(0.78,0.80) (0.21,0.19) (0.181,0.187)
2)当我“第二次”调用 JfreeChart 类时,我的示例数组中将有不同的值 (0.20,0.19) (0.8,0.79) (0.41,0.45) (0.77,0.79) (0.54,0.65)
这会持续几次(10次)所以我需要将其添加到“XYSeries”和“XYSeriesCollection”并在我第二次调用 JFreeChart 类时显示“第一次”值和“第二次”值
I am facing problems in adding points to XYSeries. I have two classes. One is Sample
(it has a main
method) and the other class is JfreeChart
(it has JfreeChart
Code). In my Sample
class I have a 2D array sample[row][2]
which has initially 10 rows, and then I need to call the JfreeChart
class and add them to XYSeries and display a scatter plot. I managed to do this, but the next time I call the Jfreechart
class my Array has 25 rows.
I need to add the values to XYSeries and plot them on a scatter plot which should display the earlier 10 rows' values with different colors and now 25 rows values with different colors… and this goes on. Can anyone give some suggestions or examples?
class Sample {
public static void main(String args[]) {
System.out.print("(X,Y) Paired Values");
double[][] sample = new double[row][2];
for (int g = 0; g < sampe.length; g++) {
for (int h = 0; h < 2; h++) {
System.out.print("" + sample[g][h] + ",");
}
}
JfreeChart sample = new JfreeChart("Demo", sample);
}
static XYDataset samplexydataset2(double[][] sample) {
XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
XYSeries series = new XYSeries("DataSet");
for (int x = 0; x < sample.length; x++) {
series.add(sample[x][0], sample[x][1]);
}
xySeriesCollection.addSeries(series);
return xySeriesCollection;
}
}
1)When I call "First Time" JfreeChart Class I will be having these Pairs in my Sample Array
(0.78,0.80)
(0.21,0.19)
(0.181,0.187)
2)When I call JfreeChart Class "Second time" I will having Diffrent values in my Sample Array
(0.20,0.19)
(0.8,0.79)
(0.41,0.45)
(0.77,0.79)
(0.54,0.65)
And this goes for few times(10 times)So I need add this to "XYSeries" and "XYSeriesCollection" and display the "First time" Values and "Second time" Values when I call Second time JFreeChart Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以向
添加新值XYSeries
使用可用的add()
方法之一,如以下 示例。如果您遇到不定行,则需要发布 sscce。附录:更仔细地查看(最近更新)您的示例的起源,一些混淆是可以理解的:根本不需要数组。下面的示例包括一个将新示例添加到第二个系列的按钮。
每个新系列都有一种新颜色,如示例所示。要更改单个颜色,建议的方法是重写渲染器的 getItemPaint() 方法,如下所示 此处。
You can add new values to the
XYSeries
using one of the availableadd()
methods, as shown in this example. If you're getting adventitious rows, you'll need to post an sscce.Addendum: Looking more closely at the (recently updated) genesis of your example, some confusion is understandable: no array is needed at all. The example below includes a button that adds new samples to a second series.
Each new series is a new color, as shown in this example. To change individual colors, the recommended way is to override the renderer's
getItemPaint()
method, as shown here.