简体   繁体   English

JFreeChart XYAreaChart设置域轴

[英]JFreeChart XYAreaChart setting Domain Axis

I have a dynamic area chart which is implemented with w mouse wheel listener tu put data on my chart through the time, I want to set my domain axis for 10 seconds only because my chart is showin all data from the beginning but I want to display only the 10 last seconds. 我有一个动态面积图,使用w鼠标滚轮监听器在整个时间内将数据放置在我的图表上,我只想将域轴设置为10秒,因为我的图表从一开始就显示在所有数据中,但我想显示最后十秒。 How to do that? 怎么做? Here's my code: 这是我的代码:

 final XYSeries series = new XYSeries("Data");

    XYSeriesCollection dataset = new XYSeriesCollection(series);

    // Creation du area chart
    JFreeChart chart = ChartFactory.createXYAreaChart("Fun Meter", "", "",
            dataset, PlotOrientation.VERTICAL, false, false, false);


    final JLabel a = new JLabel();
    // Un chartpanel pour contenir le area chart
    ChartPanel CP = new ChartPanel(chart);

    // creation d'objet plot pour ajustement de tout ce qui est graphique
    XYPlot xyPlot = (XYPlot) chart.getPlot();

    // la couleur degradée pour le remplissage du area chart
    GradientPaint gp0 = new GradientPaint(0.0f, 100.0f, new Color(50, 205,
            50), 0.0f, 100.0f, Color.red);

    xyPlot.getRenderer().setSeriesPaint(0, gp0);
    xyPlot.setBackgroundPaint(Color.black);
    xyPlot.setForegroundAlpha(0.75f);

    GradientPaint gp1 = new GradientPaint(0.0f, 100.0f, Color.black, 0.0f,
            1000.0f, new Color(153, 153, 153));

    chart.setBackgroundPaint(gp1);

    CP.addMouseWheelListener(new MouseWheelListener() {
        public void mouseWheelMoved(MouseWheelEvent e) {

            Integer rx = e.getWheelRotation();
            Wheel = Wheel - rx;
                    }
    });

    new Timer(100, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            series.add(series.getItemCount(), Wheel);
        }
    }).start();

One approach is to use a DynamicTimeSeriesCollection , shown here . 一种方法是使用DynamicTimeSeriesCollection ,显示在这里 The nMoments constructor parameter specifies the number of TimePeriod units to be retained. nMoments构造函数参数指定要保留的TimePeriod单位数。

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

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