JFreeChart - 如何将域十字线值转换为 TimeSeriesDataItem
我有一个 XYPlot,显示 TimeSeriesCollection 中的多个 TimeSeries。我希望能够获取与域十字准线单击相对应的 TimeSeriesDataItems 列表。
看起来我可以添加一个 PlotChangeListener 来通知十字线值的变化,然后我可以调用 XYPlot.getDomainCrosshairValue(),但我不知道如何使用该十字线值来获取正确的时间序列项
I have an XYPlot displaying multiple TimeSeries in a TimeSeriesCollection. I'd like to be able to get the list of TimeSeriesDataItems that correspond to a domain crosshair click.
It looks like I can add a PlotChangeListener to be notified of a change in the crosshair value and I can then call XYPlot.getDomainCrosshairValue(), but I can't see how to then use that crosshair value to get the right time series items
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终设法弄清楚了。我本来就走在正确的轨道上;添加一个 PlotChangeListener 以接收更改通知,然后获取十字准线值。因为我的域轴是 DateAxis,所以作为十字线值返回的值实际上是十字线所在日期的毫秒值。由此,我可以构造一个 Day 实例,该实例可用于从 TimeSeriesCollection 中的每个 TimeSeries 检索 TimeSeriesDataItem。
然后,您还必须向 ChartPanel 添加 MouseClickListener,以便您可以将点击委托给图表。否则你的绘图更改监听器将永远不会被调用。
I managed to figure it out eventually. I was on the right track originally; add a PlotChangeListener to be notified of a change and then get the crosshair value. Because my domain axis is a DateAxis the value returned as the crosshair value is actually the millisecond value of the date that the crosshair falls on. From that, I can construct a Day instance that can be used to retrieve the TimeSeriesDataItem from each TimeSeries in my TimeSeriesCollection.
Then you also have to add a MouseClickListener to the ChartPanel so that you can delegate clicks to the chart. Otherwise your plot change listener will never be invoked.