Git Product home page Git Product logo

jfreechart-fx's Introduction

JFreeChart-FX

Version 2.0.1, 21 February 2021.

Maven Central

Overview

JFreeChart-FX is an extension for JFreeChart that allows JFreeChart to be used in JavaFX applications.

JFreeChart sample

Include

To include JFreeChart-FX in your application:

<dependency>
    <groupId>org.jfree</groupId>
    <artifactId>org.jfree.chart.fx</artifactId>
    <version>2.0.1</version>
</dependency>

JFreeChart-FX has dependencies on:

  • JFreeChart 1.5.3
  • FXGraphics2D 2.1

Demo Programs

There are demo programs for this API provided in the following project:

https://github.com/jfree/jfree-fxdemos

History

Version 2.0.1 (21 February 2021)
  • update JFreeChart dependency to 1.5.3.
Version 2.0 (30 October 2020)
  • created a Java module org.jfree.chart.fx (requires Java 11 or later);
  • fixed a bug in ChartViewer (#7);
  • fixed a bug in ZoomHandler (#8);
  • fix a bug related to a ChartCanvas having a null chart (#12);
  • updated JFreeChart dependency to version 1.5.1;
  • updated FXGraphics2D dependency to version 2.1.
Version 1.0.1 (30 December 2017)
  • fixed a bug in ChartCanvas (#3);
  • added source files to Javadoc output.
Version 1.0.0 (5 November 2017)

Initial release after extracting the JavaFX code from the JFreeChart project.

jfreechart-fx's People

Contributors

jfree avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jfreechart-fx's Issues

ChartCanvas Positioning

The layout X and Y of the ChartCanvas are set to the X and Y values of the ChartViewer in its layoutChildren method. The works well only if the ChartViewer is placed at the point of origin (x=0 and y=0) in its surrounding container. Otherwise the ChartCanvas will be placed outside of the ChartViewer.
The layout x and y position the node inside its parent. Therefore the ChartCanvas is placed inside the Chartviewer exactly as the ChartViewer is placed in its parent node which means that the Canvas will be plaxed at X2 and Y2 in the parent node.

See javadoc of Node:

Each Node also has a read-only boundsInParent variable which specifies the bounding rectangle of the Node after all transformations have been applied, including those set in transforms, scaleX/scaleY, rotate, translateX/translateY, and layoutX/layoutY. It is called "boundsInParent" because the rectangle will be relative to the parent's coordinate system. This is the 'visual' bounds of the node. <

Example for reproduction:
Placing multiple Charts in a VBox (or HBox) will illustrate the problem pretty well, for the coordinates add up for each chart and the gaps are getting bigger.

Compile errors

TimeSeriesChartFXDemo1.java:[103,21] cannot find symbol
symbol: method setBaseShapesVisible(boolean)
location: variable renderer of type org.jfree.chart.renderer.xy.XYLineAndShapeRenderer
TimeSeriesChartFXDemo1.java:[107,21] cannot find symbol
symbol: method setBaseStroke(java.awt.BasicStroke,boolean)
location: variable renderer of type org.jfree.chart.renderer.xy.XYLineAndShapeRenderer

I built the latest jfreechart prior to this.

False file extention formats for FileChooser in ChartViewer.class

When you save an image you need to type file.png in as a file name (not just file)
I guess it should be not "png" but "*.png" etc.

wrong: new FileChooser.ExtensionFilter(
"Portable Document Format (PDF)", "pdf");

right?: new FileChooser.ExtensionFilter(
"Portable Document Format (PDF)", "*.pdf");

Unusual behavior with FlowPlot and setNodeColorSwatch

While pursuing this discussion, I encountered an unusual behavior with FlowPlot when invoking setNodeColorSwatch() with JavaFX. Using java 17.0.6, openjfx 17.0.2, jfreechart-1.5.4, org.jfree.chart.fx-2.0.1, org.jfree.fxgraphics2d-2.1.4 and the code below, I see the first result pictured. With setNodeColorSwatch(), the font is unexpectedly larger and the colors lack the intended gradient; a click anywhere on the chart results in the expected appearance.

As a workaround, evoking either of the chart changed events after show() produces the expected font size and gradients.As the color swatch is not a bound property, an explicit redraw is not unreasonable. This is a low priority issue, but I'd welcome any insight.

Without setNodeColorSwatch():
FlowPlotFXTest

With setNodeColorSwatch():
FlowPlotSwatch

With viewer.getCanvas().getChart().fireChartChanged():
FlowPlotChangeEvent

Code:

import java.awt.Color;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.fx.ChartViewer;
import org.jfree.chart.plot.flow.FlowPlot;
import org.jfree.data.flow.DefaultFlowDataset;
import org.jfree.data.flow.FlowDataset;
import org.jfree.data.flow.NodeKey;

/**
 * FlowPlot example adapted from https://github.com/jfree/flowplot.git
 */
public class FlowPlotFXTest extends Application {

    // Adapted from FlowPlotDemo1.java
    private FlowDataset<String> createDataset() {
        var dataset = new DefaultFlowDataset<String>();
        dataset.setFlow(0, "A", "X", 4);
        dataset.setFlow(0, "A", "Y", 2);
        dataset.setFlow(0, "A", "Z", 1);
        dataset.setFlow(0, "B", "X", 2);
        dataset.setFlow(0, "B", "Y", 2);
        dataset.setFlow(0, "B", "Z", 2);

        dataset.setFlow(1, "X", "D", 3);
        dataset.setFlow(1, "X", "E", 4);
        dataset.setFlow(1, "Y", "D", 5);
        dataset.setFlow(1, "Y", "E", 3);
        dataset.setFlow(1, "Z", "D", 2);
        dataset.setFlow(1, "Z", "E", 1);

        dataset.setFlow(2, "D", "H", 2);
        dataset.setFlow(2, "D", "I", 3);
        dataset.setFlow(2, "D", "J", 0);
        dataset.setFlow(2, "E", "H", 3);
        dataset.setFlow(2, "E", "I", 2);
        dataset.setFlow(2, "E", "J", 3);
        return dataset;
    }

    private JFreeChart createChart(FlowDataset dataset) {
        var plot = new FlowPlot(dataset);
        plot.setBackgroundPaint(Color.BLACK);
        plot.setDefaultNodeLabelPaint(Color.WHITE);
        plot.setDefaultNodeColor(Color.CYAN.darker());
        plot.setNodeFillColor(new NodeKey(1, "Y"), Color.MAGENTA);
        //plot.setNodeColorSwatch(FlowColors.getDefaultColors());
        var chart = new JFreeChart("FlowPlot FX Test", plot);
        return chart;
    }

    public ChartViewer createViewer() {
        var dataset = createDataset();
        var chart = createChart(dataset);
        var viewer = new ChartViewer(chart);
        viewer.setPrefSize(768, 512);
        return viewer;
    }

    @Override
    public void start(Stage stage) throws Exception {
        ChartViewer viewer = createViewer();
        stage.setTitle(viewer.getChart().getTitle().getText());
        stage.setScene(new Scene(viewer));
        stage.show();
        //viewer.getCanvas().getChart().fireChartChanged();
        //viewer.getCanvas().chartChanged(null);
    }

    public static void main(String[] args) {
        launch(args);
    }
}

ChartViewer constructor with contextMenuEnabled parameter seems that is not working

Hello @jfree ,
I realized that when I am constructing a new ChartViewer like the bellow:
this.chartViewer = new ChartViewer(chart, false);
the context menu is still not disabled on the chart. I look into the source code and looks like contextMenuEnabled field has not been used.

public ChartViewer(JFreeChart chart, boolean contextMenuEnabled) {
        this.canvas = new ChartCanvas(chart);
        this.canvas.setTooltipEnabled(true);
        this.canvas.addMouseHandler(new ZoomHandlerFX("zoom", this));
        this.setFocusTraversable(true);
        this.getChildren().add(this.canvas);
        this.zoomRectangle = new Rectangle(0.0D, 0.0D, new Color(0.0D, 0.0D, 1.0D, 0.25D));
        this.zoomRectangle.setManaged(false);
        this.zoomRectangle.setVisible(false);
        this.getChildren().add(this.zoomRectangle);
        this.contextMenu = this.createContextMenu();
        this.setOnContextMenuRequested((event) -> {
            this.contextMenu.show(this.getScene().getWindow(), event.getScreenX(), event.getScreenY());
        });
        this.contextMenu.setOnShowing((e) -> {
            this.getCanvas().setTooltipEnabled(false);
        });
        this.contextMenu.setOnHiding((e) -> {
            this.getCanvas().setTooltipEnabled(true);
        });
    }

How can I disable context menu in this case?
Thanks.

IllegalArgumentException: null source

I have the following exception:

java.lang.IllegalArgumentException: null source
	at java.util.EventObject.<init>(EventObject.java:56)
	at org.jfree.chart.fx.interaction.ChartMouseEventFX.<init>(ChartMouseEventFX.java:77)
	at org.jfree.chart.fx.interaction.DispatchHandlerFX.handleMouseMoved(DispatchHandlerFX.java:83)
	at org.jfree.chart.fx.ChartCanvas.handleMouseMoved(ChartCanvas.java:616)
	at org.jfree.chart.fx.ChartCanvas.lambda$new$2(ChartCanvas.java:192)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
	at javafx.event.Event.fireEvent(Event.java:198)
	at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
	at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
	at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
	at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:432)
	at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
	at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
	at com.sun.glass.ui.View.notifyMouse(View.java:937)
	at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at com.sun.glass.ui.gtk.GtkApplication.lambda$null$208(GtkApplication.java:245)
	at java.lang.Thread.run(Thread.java:748)

The exception can be triggered by creating a ChartViewer without an actual chart in it, e.g.:


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class ChartProblem extends Application {

	    @Override
	    public void start(Stage primaryStage) throws Exception {
	    	ChartViewer cv = new ChartViewer();
	    	cv.setMinSize(800, 600);

	        Scene scene = new Scene(cv, 400, 400);
	        primaryStage.setScene(scene);
	        primaryStage.show();
	    }

	    public static void main(String[] args) {
	        launch(args);
	    }
}

Scrolling example with slider.

Hello,
can you paste or give me some example how use scrolling with javafx sliders with your ChartCanvas?
Thanks for help!

CrosshairOverlayFX NPE with CombinedDomainXYPlot

It seems that CrosshairOverlayFX currently doesn't support CombinedDomainXYPlot. When you add it as an overlay (viewer.canvas.addOverlay(crosshair)) it will issue a NPE because it's unable to find a valid plot instance here:

A potential solution is to let CrosshairOverlayFX accept the right plot in the constructor. In this case, and I'm not sure the best way to account for this, you'll also need to update the yy value computation (e.g. for vertical combined plots) so that the crosshair shows at the right height:

double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);

For example, if the top chart has a weight of 2 and the bottom chart has a weight of 1, then the computation above needs to be multiplied by 2/3.

IllegalArgumentException seen when using LogAxis and clicking anywhere outside data plot area

I ran into a scenario where clicking outside the data plot area (in the legend area, axis labels area, etc) while using a LogAxis can result in an IllegalArgumentException. After this occurs the chart is then essentially non-interactive and does not respond to user input such as drag to zoom.

Stack Trace:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: A positive range length is required: Range[0.05449587578346141,0.05449587578346141]
	at org.jfree.chart.axis.ValueAxis.setRange(ValueAxis.java:1278)
	at org.jfree.chart.axis.ValueAxis.setRange(ValueAxis.java:1256)
	at org.jfree.chart.axis.LogAxis.zoomRange(LogAxis.java:953)
	at org.jfree.chart.plot.XYPlot.zoomDomainAxes(XYPlot.java:5119)
	at org.jfree.chart.fx.interaction.ZoomHandlerFX.handleMouseReleased(ZoomHandlerFX.java:234)
	at org.jfree.chart.fx.ChartCanvas.handleMouseReleased(ChartCanvas.java:648)
	at org.jfree.chart.fx.ChartCanvas.lambda$new$6(ChartCanvas.java:196)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
	at javafx.event.Event.fireEvent(Event.java:198)
	at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
	at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
	at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
	at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417)
	at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
	at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
	at com.sun.glass.ui.View.notifyMouse(View.java:937)

Complete self contained example:

/**
 * Click in the axis label area to see IllegalArgumentException followed by erratic behavior
 */
public class IllegalArgumentBug extends Application
{
    public static void main(String[] args)
    {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
        XYSeriesCollection primarySeriesCollection = new XYSeriesCollection();

        JFreeChart chart = ChartFactory.createXYLineChart(
            "",
            "",
            "",
            primarySeriesCollection,
            PlotOrientation.VERTICAL,
            true,
            false,
            false);

        XYPlot plot = chart.getXYPlot();
        plot.setDomainAxis(new LogAxis("X"));
        plot.setRangeAxis(new LogAxis("Y"));

        ChartViewer chartViewer = new ChartViewer(chart);
        primaryStage.setScene(new Scene(chartViewer));

        primaryStage.show();
    }
}

Font rendering issue when using a transparent chart background

Hello,

it's great to see offical JavaFX support in JFreeChart - thanks a lot!

In my application I need to set a transparent background for the chart because the chart needs to have the same background color as the dialog where it is shown. This is done by setting the background color with alpha 0.0.
Unfortunately this causes a font rendering issue since JFreeChart-FX 1.0, this was not the case with the unofficial/unreleased version before. All the rendered text (e.g. for the axis, titles, legends, ...) looks very blurry now.

I'm adding a modified version of your demo applications and some screenshots which show the problem. In my application it looks even worse, I'm using other fonts there.

Not transparent, proper rendering:

demo-not_transparent

Transparent background, blurry rendering:
demo-transparent_blurry

Bye, Stefan

Heavy performance loss using CrosshairOverlayFX

I am happy to see that there is a JavaFX wrapper for JFreeChart!

After moving with my charting application from Swing to JavaFX i discovered that the CrosshairOverlayFX is delayed on my CombinedXYPlot with 750 candlesticks as DefaultHighLowDataset. Adding more data to the chart (XYPlots as sub plots and TimeSeriesCollection data of the same size) makes the cross hair overlay so slow that it cannot be used seriously.
I have enable caching in the ChartCanvas Region but it does not change anything. Are there other possibilities to improve performance of the overlay? In swing the cross hair overlay worked perfectly and very fast with exact the same settings and data

Different behaviour in JavaFX/Swing node

Hey,

we noticed different behaviour of a chart placed in a swing or java fx node on at least two occasions:

  1. A dataset of the same type increased its bar width on zoom in. Manually overriding the getX etc. method fixed that. See the changes in this this commit.
    mzmine/mzmine@40f3034
    grafik
    Left is Swing, right is JavaFX. (without the fix)

  2. In the same screenshot, you can see the left plot has a joined domain axis, whereas the left one does not. Both plots are an instance of CombinedDomainXYPlot. The gap is set to 0 on creation of both of those charts. In Swing it works, in java fx it does not. For some reason though, if the plot is cloned, moved to a new window and then a theme is applied, the axis join.

I hope this is enough information, if you need to know more please let me know.

Best regards
Steffen

Upload actual snapshot version to Nexus

Hello,
please upload your actual version 2.0-snapshot to nexus snapshot repository. It is still missing...

 <groupId>org.jfree</groupId>
 <artifactId>org.jfree.chart.fx</artifactId>
 <version>2.0-SNAPSHOT</version>
 <packaging>jar</packaging>

<distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>    

Thanks!

DynamicDataDemo2 rewrite in jfreechart-fx can not run stable

You can test my code below ,after run maybe 5 mins data still run but the ui shutdown.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.fx.ChartViewer;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.DefaultXYItemRenderer;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

/**
 * A demo showing the display of JFreeChart within a JavaFX application.
 * 
 * The ChartCanvas code is based on: 
 * http://dlemmermann.wordpress.com/2014/04/10/javafx-tip-1-resizable-canvas/
 * 
 */
public class DynamicTimeSeriesChartFXDemo2 extends Application {

    /**
     * Creates a chart.
     *
     *
     * @return A chart.
     */
    private static JFreeChart createChart() {

        final TimeSeriesCollection dataset1 = new TimeSeriesCollection(series1);
        final TimeSeriesCollection dataset2 = new TimeSeriesCollection(series2);
        final JFreeChart chart = ChartFactory.createTimeSeriesChart(
                "Dynamic Data Demo 2", "Time", "Value", dataset1, true, true, false
        );
        chart.setBackgroundPaint(Color.white);

        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
        final ValueAxis axis = plot.getDomainAxis();
        axis.setAutoRange(true);
        axis.setFixedAutoRange(60000.0);  // 60 seconds

        plot.setDataset(1, dataset2);
        final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
        rangeAxis2.setAutoRangeIncludesZero(false);
        plot.setRenderer(1, new DefaultXYItemRenderer());
        plot.setRangeAxis(1, rangeAxis2);
        plot.mapDatasetToRangeAxis(1, 1);

        return chart;
    }

    /**
     * Creates a dataset, consisting of two series of monthly data.
     *
     * @return the dataset.
     */


    private static TimeSeries series1;
    private static TimeSeries series2;
    private static double lastValue1 = 100.0;
    private static double lastValue2 = 500.0;


    private static void createDataset() {

        series1 = new TimeSeries("Random 1");//, Millisecond.class
        series2 = new TimeSeries("Random 2");//, Millisecond.class

    }




    private Timer timer;
    private static final int FAST = 500;

    @Override 
    public void start(Stage stage) throws Exception {
        createDataset();
        JFreeChart chart = createChart();
        ChartViewer viewer = new ChartViewer(chart);

        timer = new Timer(FAST, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                double factor = 0.90 + 0.2 * Math.random();
                lastValue1 = lastValue1 * factor;
                Millisecond now = new Millisecond();
                System.out.println("Now = " + now.toString());
                series1.add(new Millisecond(), lastValue1);


                factor = 0.90 + 0.2 * Math.random();
                lastValue2 = lastValue2 * factor;
                now = new Millisecond();
                System.out.println("Now = " + now.toString());
                series2.add(new Millisecond(), lastValue2);
            }
        });

        stage.setScene(new Scene(viewer)); 
        stage.setTitle("JFreeChart: TimeSeriesFXDemo1.java"); 
        stage.setWidth(700);
        stage.setHeight(390);
        stage.show();

        timer.start();
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
  
}

Zooming by clicking and draging the mouse not working in all directions.

While clicking and draging the mouse works fine when the origin is a pont thats to the upper left to the destination, any other direction does not work, it does not even show a blue "lasso" and resets the zoom level.

I am sorry for creating the issue if this is intended as a feature, but I could not find a way to turn it off.

Charts cannot be seen if pane created in FXML

The crosshair overlay example was modified to appear in a pane defined in the FXML file.
in the controller declared:

// some code here//
@FXML
AnchorPane pane;
// Blah-blah
some code...//
@OverRide
public void initialize(URL url, ResourceBundle rb) {
freeCharts charts = new freeCharts();
XYDataset dataset = charts.createDataset();
JFreeChart chart = charts.createChart(dataset);
ChartViewer viewer = new ChartViewer(chart);
pane.getChildren().add(viewer);

Does not produce a visible chart.

Crosshair performance over a huge XYZDataset

Hello, I'm using a spectrogram like plots that consists of XYZDataset with huge amount of processed data.
view for example:
изображение
x.lenght * y.length = 897 122 304‬ and each has z value (color intensity).

I need a tool like domain crosshair on chartMouseEventFX to highlight data. When the amount of data grows I got terrible time lags of the crosshair.
But when I apply this crosshair on empty dataset it works fine in the same ranges of AxisRange and DomainRange. I understand that the lag reason is a computations with java2DToValue over dataArea.
Is there a way to get "domain axis specific" value from chartMouseEventFX to avoid excessive computations of filled dataArea?

HBox does not show all ChartViewer instances

Wrapping several ChartViewer instances directly in a HBox shows only some of them. The ChartViewer instances are too big. Taking a look with ScenicView at the UI reveals, that each viewer instance uses n times the size which should be needed. When the ChartViewer gets wrapped into a StackPane, it works like expected.

The code at gist.github.com shows the effect and also a possible workaround. Use numberOfCharts and showBug to change the number of visible charts and to activate the workaround. The used chart and the data are taken from the BarChartFXDemo1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.