具有不同点颜色和大小的JFreeChart散点图 [英] JFreeChart scatter chart with varying point colours and sizes

查看:38
本文介绍了具有不同点颜色和大小的JFreeChart散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在散点图上绘制一些数据:xy,其中系列中的每个点都有point sizecolor.这可能吗?

I want to plot some data on a scatter plot: x against y where each point in the series has a point size and a color. Is this possible?

举个例子

int[] x = {1,2,3,4,5};
int[] y = {2,4,6,8,10};

int[] pointSize = {10,20,40,15,25}; //pixels
Color[] colors = {rgb1,rgb2,rgb3,rgb4,rgb5};

我对JFree还是很陌生,因此,如果您可以发布一些完美的示例代码:D

I'm quite new to JFree so if you could post some example code that would be perfect :D

推荐答案

您可以覆盖XYShapeRenderer#XYShapeRendererXYShapeRenderer#getItemShape

final Shape[] pointSize = {createCircle(10),createCircle(20),createCircle(40),createCircle(15),createCircle(25)}; //pixels
final Color[] colors = {Color.red,Color.yellow,Color.pink,Color.blue,Color.cyan};

plot.setRenderer(new XYShapeRenderer() {
   @Override
   public Paint getItemPaint(int row, int column) {
     try {
       return colors[column];
     } catch (Exception e) {
       return colors[0];
     }
}

  @Override
  public Shape getItemShape(int row, int column) {
    try {
      return pointSize[column];
    } catch (Exception e) {
      return pointSize[0];
   }
}
});

我正在使用辅助函数来创建点:

I'm using a helper function to create the points:

private static Shape CreateCircle(double size){
     return new Ellipse2D.Double(-size/2,-size/2,size,size);
}

这将创建如下图表:

您还可以使用

该图像来自JFreeChart文档

THis image is from the JFreeChart documentation

这篇关于具有不同点颜色和大小的JFreeChart散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆