JFreeChart:如何获取XYItemEntity的坐标? [英] JFreeChart: how to get coordinates of an XYItemEntity?

查看:70
本文介绍了JFreeChart:如何获取XYItemEntity的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这个问题上停留了很长时间了.我需要属于XYItemEntity的某些点的坐标.我正在绘制烛台图,想知道该商品的开盘价,收盘价,最高价,最低价的坐标是什么.

I've been stuck with this problem for quite some time. I need coordinates of certain points that belong to XYItemEntity. I'm drawing candlestick charts, and want to know what are the coordinates of open, close, high, low prices of the item.

有什么方法可以实现?

问题类似于此问题:

The question is similar to this one: https://stackoverflow.com/questions/30801444/jfreecharthow-to-get-coordinates-of-a-chartentity-and-snap-mouse-cursor-to-the but since then I changed the approach. What I want to achieve is the following: I'm drawing a Candelistick chart. As mentioned above I want the user to be able to "snap" mouse to one of the 4 values of the candle: high, low, open, close. In order to implement this feature I figured I would build a collection of Points on ChartPanel that would correspond to those values of all the candles currently being displayed. Then, by adding ChartMouseListener to the ChartPanel, in the chartMouseMoved method I would check if the cursor is in close proximity to any of those points. Here I add MouseChartListener to the ChartPanel:

chartPanel.addChartMouseListener(new MyChartMouseListener());

在这种方法中,我要检查光标是否在任何蜡烛附近:

In this method I want to check if the cursor is near any of the candles:

@Override
    public void chartMouseClicked(ChartMouseEvent chartMouseEvent) {
        int x = chartMouseEvent.getTrigger().getX();
        int y = chartMouseEvent.getTrigger().getY();
        getCandleCloseToCursor(x,y);
    }

我的getCandleCloseToCursor方法应该是什么样?

How should my getCandleCloseToCursor method look like?

private Point getCandleCloseToCursor(int x, int y) {
        //return point that belongs to the candle near the x,y position;
        //either high, low, close, open position
        return null;
    }

希望现在变得更清楚了.

Hopefully it's a little bit more clear now.

推荐答案

A TableModel 访问,获取对OHLCDataset数据集的引用,并使用其访问器方法来履行TableModel合同,如此处.确切的详细信息取决于您的要求,但是您可以利用JTable

A CandlestickRenderer collects ChartEntity information in its implementation of drawItem(), but it lacks the resolution you want. The required geometry is calculated on the fly for each item and never stored explicitly. Absent an entirely new renderer, one approach would be to update an adjacent JTable with relevant data taken from the OHLCDataset. Give your TableModel access to a ChartMouseListener, obtain a reference to the OHLCDataset dataset, and use its accessor methods to fulfill the TableModel contract, as shown here. The exact details depend on your requirements, but you may be able to leverage JTable filtering.

这篇关于JFreeChart:如何获取XYItemEntity的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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