如何在 JChart2D 中标记特殊数据点?

发布于 2024-12-03 10:43:13 字数 1033 浏览 1 评论 0原文

在 JChart2D 中,一系列的点可以用小圆圈或穿过这些点的线来绘制。我需要引起用户对某些特定点的注意。

我如何用实心圆圈或其他类型的符号来标记偶尔出现的点。

提供的垂直条形图似乎将整个图更改为垂直条形图(在它发生的点以及“追溯”到较旧的点)。我不想那样。我只需要让一个点看起来很特别,例如 X=5 处的点。

    Chart2D chart = new Chart2D();
    ITrace2D myTrace = new Trace2DLtd(100); 
    myTrace.setColor(Color.RED);
    myTrace.setTracePainter(new TracePainterDisc()); // circle; not filled

    chart.addTrace(myTrace);

    JFrame frame = new JFrame(Constants.graphTitle);
    frame.getContentPane().add(chart);

    frame.setSize(200, 200);
    frame.addWindowListener(
        new WindowAdapter(){
          public void windowClosing(WindowEvent e){
              System.exit(0);
          }
        }
      );
    frame.setVisible(true);

    List<Point> list = Helper.makeList();
    for (Point p: list)
    {
        if (p.x != 5)
            myTrace.addPoint(p.x, p.y);
        else
        {
            // MAKE THIS POINT LOOK DIFFERENT, BUT HOW?
            myTrace.addPoint(p.x, p.y);
        }
    }
  }
}

In JChart2D points from a series can be plotted with little circles or a line drawn through the points. I need to draw the user's attention to certain specific points.

How would I mark the occasional point with filled-in circles or some other kind of symbol.

The vertical bar painter provided, seems to change the entire plot to a vertical bar chart (at the point it occurs and also "retroactively" to the older points). I do not want that. I just need to make a single point look special, for example, the point at X=5.

    Chart2D chart = new Chart2D();
    ITrace2D myTrace = new Trace2DLtd(100); 
    myTrace.setColor(Color.RED);
    myTrace.setTracePainter(new TracePainterDisc()); // circle; not filled

    chart.addTrace(myTrace);

    JFrame frame = new JFrame(Constants.graphTitle);
    frame.getContentPane().add(chart);

    frame.setSize(200, 200);
    frame.addWindowListener(
        new WindowAdapter(){
          public void windowClosing(WindowEvent e){
              System.exit(0);
          }
        }
      );
    frame.setVisible(true);

    List<Point> list = Helper.makeList();
    for (Point p: list)
    {
        if (p.x != 5)
            myTrace.addPoint(p.x, p.y);
        else
        {
            // MAKE THIS POINT LOOK DIFFERENT, BUT HOW?
            myTrace.addPoint(p.x, p.y);
        }
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˇ宁静的妩媚 2024-12-10 10:43:13

将相关代码替换为:

PointPainterDisc icon = new PointPainterDisc(); 
icon.setDiscSize(20); // make it bigger than the others
icon.setColorFill(Color.BLUE); // choose a color not used by the others
TracePoint2D point = new TracePoint2D(p.x, p.y);
point.addAdditionalPointPainter(icon);
myTrace.addPoint(point);

Replace the relevant code with this:

PointPainterDisc icon = new PointPainterDisc(); 
icon.setDiscSize(20); // make it bigger than the others
icon.setColorFill(Color.BLUE); // choose a color not used by the others
TracePoint2D point = new TracePoint2D(p.x, p.y);
point.addAdditionalPointPainter(icon);
myTrace.addPoint(point);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文