根据滑块的当前值在JFreeChart中渲染单个点 [英] Rendering a single point in a JFreeChart based on the current Value of a Slider

查看:64
本文介绍了根据滑块的当前值在JFreeChart中渲染单个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java的了解还不如我想做的那么多,所以我发现我目前的任务颇具挑战性:

I'm not yet as much into Java as I'd like to be, so I find my current task to be quite a bit challenging:

  • 显示其他类别中收集的数据的图表.
  • 滑块的最终值由图表中使用的数据集中的最后一个条目确定.
  • 播放按钮目前不执行任何操作,只是让滑块以5步打勾,直到再次暂停为止.

我现在的问题是:我应该根据滑块当前显示的值来一次突出显示图表中的一项.

My problem right now is: I am supposed to highlight one item at a time in the chart based on which value the slider currently shows.

说实话...我还不习惯渲染器.

And to be honest... I'm not yet used to renderers yet.

如果我理解正确,我将需要使用

If I understood it correctly I would need to use

 renderer.drawItem(java.awt.Graphics2D g2,
          XYItemRendererState state,
          java.awt.geom.Rectangle2D dataArea,
          PlotRenderingInfo info,
          XYPlot plot,
          ValueAxis domainAxis,
          ValueAxis rangeAxis,
          XYDataset dataset,
          int series,
          int item,
          CrosshairState crosshairState,
          int pass)

但是我对方法及其参数一无所知,也不知道如何初始化它们.

but I am totally inexperienced with as well the method as its arguments and got no idea how to initialize them.

我的意思是...我从图表中获得了一个绘图,一个数据集和2个系列,我还建议项目"是该系列中要突出显示的项目的索引,我可以从滑块将其转换为-值.

I mean... I got a plot, a dataset, and 2 series from the chart, I also suggest "item" would be the index of the item to highlight in the series, which I could convert from the slider-value.

不幸的是,谷歌对此感到困扰,因为我得到的只是我上面在大约50个不同页面上发布的代码(我后来放弃了).

Unfortunately plaguing google about it turned out to be rather frustrating since all I got was the very code I posted above on about 50 different pages (I gave up after).

我想知道……首先,我什至将要使用正确的方法,并以这样的要求为耻,以至于如何使用它.

I would like to know ... first of all if I am even about to use the correct method and, as ashamed as I am to ask like this... how to use it.

好吧...期待一些答案,并...谢谢.

Well... looking forward to some answers and... thanks in advance.

推荐答案

好吧,我现在以不同于预期的方式解决了我的问题,但这对我来说很好.

Well, I now solved my problem in a different way than I intended to but it works out just fine for me.

我没有直接在曲线上突出显示一个点,而只是添加了一个Domainmarker,它将根据滑块当前显示的值进行调整.

Instead of highlighting a point in the curves I just simply add a Domainmarker that would adjust based on the value the slider currently shows.

class1 TestSlider

class1 TestSlider

private HashSet<SliderListener> sliderListenerSet = new HashSet<SliderListener>();

public void addSliderListener(SliderListener Listener){
    sliderListenerSet.add(Listener);
}

slider.addChangeListener(this);

public void stateChanged(ChangeEvent e) {
    // TODO Auto-generated method stub
    JSlider source = (JSlider)e.getSource();
    if (!source.getValueIsAdjusting()) {
            fireSliderChanged();
    }
} 

public void fireSliderChanged(){
    for (SliderListener currentListener : sliderListenerSet)
        currentListener.sliderValueChanged();
}

class2 SliderListener

class2 SliderListener

public interface SliderListener extends EventListener{

public void SliderValueChanged();
}

class3图表

Marker marker = new ValueMarker(0);
plot.addDomainMarker(marker); //so that it would be there at the beginning
TestSlider ts = new TestSlider();

ts.addSliderListener(new SliderListener(){

        @Override
        public void sliderValueChanged() {

            plot.removeDomainMarker(marker); //I only want one of them at a time - the one with the value the slider is currently showing so remove the old one...
            marker = new ValueMarker(ts.slider.getValue());
            plot.addDomainMarker(marker); // ... and add the one with the new value
        }

    });

}

我尽力使它尽可能简短和通用,我希望我不要删减任何重要的内容.好吧,我仍然是这个网站的新手,所以...如果我在某个地方犯了一个错误,可以随时告诉我.

I tried to keep it as short and universal as I could and I hope I didnt cut out anything important. Well, I'm still new to this site, so... in case I did a mistake somewhere feel free to tell me.

这篇关于根据滑块的当前值在JFreeChart中渲染单个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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