简体   繁体   English

在JFreeChart中监听缩放重置事件

[英]Listening for zoom reset event in JFreeChart

如何收听JFreeChart的缩放重置事件?

I did it using this: 我这样做的:

ChartPanel DCP=new ChartPanel(DailyChart){
    @Override
    public void restoreAutoBounds(){
        super.restoreAutoDomainBounds();
        super.restoreAutoRangeBounds();

        XYPlot plot=(XYPlot)getChart().getPlot();

        Calendar Cal=Calendar.getInstance();
        String dayName=Cal.getDisplayName(Calendar.DAY_OF_WEEK,Calendar.SHORT,new Locale("en", "us")).toLowerCase();
        String tmp[]=((String)Configurations.getWeeklyWorkingSchedule().get(dayName).get("start")).split(":");
        Cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(tmp[0]));
        Cal.set(Calendar.MINUTE, Integer.parseInt(tmp[1]));
        Cal.set(Calendar.SECOND, 0);
        long start=Cal.getTimeInMillis();
        tmp=((String)Configurations.getWeeklyWorkingSchedule().get(dayName).get("end")).split(":");
        Cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(tmp[0]));
        Cal.set(Calendar.MINUTE, Integer.parseInt(tmp[1]));
        Cal.set(Calendar.SECOND, 0);
        long end=Cal.getTimeInMillis();

        plot.getDomainAxis().setAutoRange(false);
        plot.getDomainAxis().setRange(start,end);
    }
};
DCP.restoreAutoBounds();

Thank You all. 谢谢你们。

I'll just add up on @trashgod suggestion, in case you want to disable zoom reset on a specific axis: create an overriden ChartPanel where you either "null" restoreAutoDomainBounds() or restoreAutoRangeBounds() , as shown below. 如果您要禁用特定轴上的缩放重置,我将仅添加@trashgod建议:创建一个重写的ChartPanel ,在其中您可以“ null” restoreAutoDomainBounds()restoreAutoRangeBounds() ,如下所示。

That can be useful when you control the viewing area from different components than the chart itself (in my case: the X axis is set by the program but the user can freely zoom in/out the Y axis). 当您从图表本身以外的其他组件控制查看区域时,这很有用(在我的情况下:X轴由程序设置,但用户可以自由放大/缩小Y轴)。

ChartPanel cp = new ChartPanel(null) {
    @Override public void restoreAutoDomainBounds() {
        // Empty body: do not reset X zoom
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM