1

我需要在 XYPlot 上绘制大量数据(150-250 点/秒 * 180 秒)。所以如果我使用自动量程方法,它有点粗糙。如果我放大绘图,我只会看到一个数据范围(例如 10.25 到 14.50)。它很好,而且效果很好,但如果我看到完整的范围会更好,但分辨率更好.

是否有可能放大绘图,并额外调整绘图区域的大小(这样你就有更多的空间来打印绘图),以便显示整个范围(例如从 0 到 180 秒)而不仅仅是一个部分?

到目前为止,我尝试的是在没有缩放的情况下拥有一个固定的大图,但它不可用(尺寸为 1200x15000)。

提前致谢!

4

2 回答 2

4

如此处所示,覆盖getPreferredSize()以返回您想要的ChartPanelpack()封闭框架的大小。通过应用获得的结果将JFrame.MAXIMIZED_BOTHsetExtendedState()用户选择的分辨率下最大限度地利用屏幕,但如果可用,您可以尝试不同的显示模式

于 2013-07-28T15:53:29.193 回答
1

我使用了垃圾邮件建议的 getPreferredSize() 方法。我扩展org.jfree.chart.MouseWheelHandler并实现了一个新的 handleZoomable 方法,如下所示。


package org.jfree.chart;

import java.awt.Dimension;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.Point2D;
import java.io.Serializable;

import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.Zoomable;

/** http://stackoverflow.com/questions/17908498/jfreechart-auto-resize-on-zoom */
class MouseWheelHandlerResize extends MouseWheelHandler {

    /** The chart panel. */
    private ChartPanel chartPanel;

    /** The zoom factor. */
    double zoomFactor;

    /** minimum size */
    final int MIN_SIZE = 300;

    /** maximal size */
    final int MAX_SIZE = 20000;

    public MouseWheelHandlerResize(ChartPanel chartPanel) {
        super(chartPanel);
        this.chartPanel = chartPanel;
        this.zoomFactor = 0.05;
    }

    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
        JFreeChart chart = this.chartPanel.getChart();
        if (chart == null) {
            return;
        }
        Plot plot = chart.getPlot();
        if (plot instanceof Zoomable) {
            Zoomable zoomable = (Zoomable) plot;
            handleZoomable(zoomable, e);
        }
        else if (plot instanceof PiePlot) {
            PiePlot pp = (PiePlot) plot;
            pp.handleMouseWheelRotation(e.getWheelRotation());
        }
    }

    private void handleZoomable(Zoomable zoomable, MouseWheelEvent e) {
        // don't zoom unless the mouse pointer is in the plot's data area
        ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
        PlotRenderingInfo pinfo = info.getPlotInfo();
        Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint());
        if (!pinfo.getDataArea().contains(p)) {
            return;
        }

        Plot plot = (Plot) zoomable;
        // do not notify while zooming each axis
        boolean notifyState = plot.isNotify();
        plot.setNotify(false);
        int clicks = e.getWheelRotation();
        double zf = 1.0 + this.zoomFactor;
        if (clicks < 0) {
            zf = 1.0 / zf;
        }
        final Dimension dim = this.chartPanel.getPreferredSize();
        this.chartPanel.setPreferredSize(new Dimension((int)(Math.min(Math.max(MIN_SIZE, dim.width)*zf, MAX_SIZE)), (int)(dim.height)));        
        this.chartPanel.validate();
        this.chartPanel.updateUI();
        plot.setNotify(notifyState);  // this generates the change event too
    }

}

org.jfree.chart.ChartPanel课堂上,我刚刚将setMouseWheelEnabled方法修改为:


public void setMouseWheelEnabled(boolean flag) {
        if (flag && this.mouseWheelHandler == null) {
            this.mouseWheelHandler = new MouseWheelHandlerResize(this);
        }
        else if (!flag && this.mouseWheelHandler != null) {
            removeMouseWheelListener(this.mouseWheelHandler);
            this.mouseWheelHandler = null;
        }
    }

现在,位于滚动视图中的 CharPanel 会调整大小并放大。

于 2013-07-29T11:46:33.427 回答