java.lang.Object
javafx.scene.Node
javafx.scene.canvas.Canvas
org.jfree.chart.fx.ChartCanvas
- All Implemented Interfaces:
EventListener,javafx.css.Styleable,javafx.event.EventTarget,org.jfree.chart.event.ChartChangeListener,org.jfree.chart.event.OverlayChangeListener
public class ChartCanvas extends javafx.scene.canvas.Canvas implements org.jfree.chart.event.ChartChangeListener, org.jfree.chart.event.OverlayChangeListener
A canvas for displaying a
JFreeChart in JavaFX. You can use the
canvas directly to display charts, but usually the ChartViewer
class (which embeds a canvas) is a better option as it provides additional
features.
The canvas installs several default mouse handlers, if you don't like the behaviour provided by these you can retrieve the handler by ID and disable or remove it (the IDs are "tooltip", "scroll", "anchor", "pan" and "dispatch").
The FontSmoothingType for the underlying GraphicsContext is
set to FontSmoothingType.LCD as this gives better results on the
systems we've tested on. You can modify this using
getGraphicsContext().setFontSmoothingType(yourValue).
-
Property Summary
Properties inherited from class javafx.scene.canvas.Canvas
height, widthProperties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible -
Field Summary
Fields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT -
Constructor Summary
Constructors Constructor Description ChartCanvas(org.jfree.chart.JFreeChart chart)Creates a new canvas to display the supplied chart in JavaFX. -
Method Summary
Modifier and Type Method Description voidaddAuxiliaryMouseHandler(MouseHandlerFX handler)Adds a handler to the list of auxiliary handlers.voidaddChartMouseListener(ChartMouseListenerFX listener)Registers a listener to receiveChartMouseEventnotifications.voidaddMouseHandler(MouseHandlerFX handler)Adds a mouse handler to the list of available handlers (handlers that are candidates to take the position of live handler).voidaddOverlay(OverlayFX overlay)Add an overlay to the canvas.voidchartChanged(org.jfree.chart.event.ChartChangeEvent event)Receives a notification from the chart that it has been changed and responds by redrawing the chart entirely.voidclearLiveHandler()Clears the current live handler.voiddraw()Draws the content of the canvas and updates therenderingInfoattribute with the latest rendering information.Rectangle2DfindDataArea(Point2D point)Returns the data area (the area inside the axes) for the plot or subplot.Point2DgetAnchor()Returns the anchor point.org.jfree.chart.JFreeChartgetChart()Returns the chart that is being displayed by this node.List<ChartMouseListenerFX>getChartMouseListeners()Returns a (newly created) list containing the listeners currently registered with the canvas.MouseHandlerFXgetMouseHandler(String id)Returns the mouse handler with the specified ID, ornullif there is no handler with that ID.org.jfree.chart.ChartRenderingInfogetRenderingInfo()Returns the rendering info from the most recent drawing of the chart.protected voidhandleScroll(javafx.scene.input.ScrollEvent e)Handles a scroll event by passing it on to the registered handlers.booleanisDomainZoomable()Returns the flag that determines whether or not zooming is enabled for the domain axis.booleanisRangeZoomable()Returns the flag that determines whether or not zooming is enabled for the range axis.booleanisResizable()Returntrueto indicate the canvas is resizable.booleanisTooltipEnabled()Returns the flag that controls whether or not tooltips are enabled.voidoverlayChanged(org.jfree.chart.event.OverlayChangeEvent event)Handles a change to an overlay by repainting the chart canvas.voidremoveAuxiliaryMouseHandler(MouseHandlerFX handler)Removes a handler from the list of auxiliary handlers.voidremoveChartMouseListener(ChartMouseListenerFX listener)Removes a listener from the list of objects listening for chart mouse events.voidremoveMouseHandler(MouseHandlerFX handler)Removes a handler from the list of available handlers.voidremoveOverlay(OverlayFX overlay)Removes an overlay from the canvas.voidsetAnchor(Point2D anchor)Set the anchor point and forces a redraw of the chart (the anchor point is used to determine the position of the crosshairs on the chart, if they are visible).voidsetChart(org.jfree.chart.JFreeChart chart)Sets the chart to be displayed by this node.voidsetDomainZoomable(boolean zoomable)Sets the flag that controls whether or not domain axis zooming is enabled.voidsetRangeZoomable(boolean zoomable)Sets the flag that controls whether or not range axis zooming is enabled.voidsetTooltip(String text, double x, double y)Sets the tooltip text, with the (x, y) location being used for the anchor.voidsetTooltipEnabled(boolean tooltipEnabled)Sets the flag that controls whether or not tooltips are enabled.Methods inherited from class javafx.scene.canvas.Canvas
getGraphicsContext2D, getHeight, getWidth, heightProperty, setHeight, setWidth, widthPropertyMethods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBaselineOffset, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClassCssMetaData, getClip, getContentBias, getCssMetaData, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, maxHeight, maxWidth, minHeight, minWidth, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, prefHeight, prefWidth, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, resize, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visiblePropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javafx.css.Styleable
getStyleableNode
-
Constructor Details
-
ChartCanvas
Creates a new canvas to display the supplied chart in JavaFX. Ifchartisnull, a blank canvas will be displayed.- Parameters:
chart- the chart (nullpermitted).
-
-
Method Details
-
getChart
Returns the chart that is being displayed by this node.- Returns:
- The chart (possibly
null).
-
setChart
Sets the chart to be displayed by this node.- Parameters:
chart- the chart (nullpermitted).
-
isDomainZoomable
Returns the flag that determines whether or not zooming is enabled for the domain axis.- Returns:
- A boolean.
-
setDomainZoomable
Sets the flag that controls whether or not domain axis zooming is enabled. If the underlying plot does not support domain axis zooming, then setting this flag totruewill have no effect.- Parameters:
zoomable- the new flag value.
-
isRangeZoomable
Returns the flag that determines whether or not zooming is enabled for the range axis.- Returns:
- A boolean.
-
setRangeZoomable
Sets the flag that controls whether or not range axis zooming is enabled. If the underlying plot does not support range axis zooming, then setting this flag totruewill have no effect.- Parameters:
zoomable- the new flag value.
-
getRenderingInfo
Returns the rendering info from the most recent drawing of the chart.- Returns:
- The rendering info (possibly
null).
-
isTooltipEnabled
Returns the flag that controls whether or not tooltips are enabled. The default value istrue. TheTooltipHandlerFXclass will only update the tooltip if this flag is set totrue.- Returns:
- The flag.
-
setTooltipEnabled
Sets the flag that controls whether or not tooltips are enabled.- Parameters:
tooltipEnabled- the new flag value.
-
getAnchor
Returns the anchor point. This is the last point on the canvas that the user clicked with the mouse, and is used during chart rendering to determine the position of crosshairs (if visible).- Returns:
- The anchor point (possibly
null).
-
setAnchor
Set the anchor point and forces a redraw of the chart (the anchor point is used to determine the position of the crosshairs on the chart, if they are visible).- Parameters:
anchor- the anchor (nullpermitted).
-
addOverlay
Add an overlay to the canvas.- Parameters:
overlay- the overlay (nullnot permitted).
-
removeOverlay
Removes an overlay from the canvas.- Parameters:
overlay- the overlay to remove (nullnot permitted).
-
overlayChanged
Handles a change to an overlay by repainting the chart canvas.- Specified by:
overlayChangedin interfaceorg.jfree.chart.event.OverlayChangeListener- Parameters:
event- the event.
-
getChartMouseListeners
Returns a (newly created) list containing the listeners currently registered with the canvas.- Returns:
- A list of listeners (possibly empty but never
null).
-
addChartMouseListener
Registers a listener to receiveChartMouseEventnotifications.- Parameters:
listener- the listener (nullnot permitted).
-
removeChartMouseListener
Removes a listener from the list of objects listening for chart mouse events.- Parameters:
listener- the listener.
-
getMouseHandler
Returns the mouse handler with the specified ID, ornullif there is no handler with that ID. This method will look for handlers in both the regular and auxiliary handler lists.- Parameters:
id- the ID (nullnot permitted).- Returns:
- The handler with the specified ID
-
addMouseHandler
Adds a mouse handler to the list of available handlers (handlers that are candidates to take the position of live handler). The handler must have an ID that uniquely identifies it amongst the handlers registered with this canvas.- Parameters:
handler- the handler (nullnot permitted).
-
removeMouseHandler
Removes a handler from the list of available handlers.- Parameters:
handler- the handler (nullnot permitted).
-
addAuxiliaryMouseHandler
Adds a handler to the list of auxiliary handlers. The handler must have an ID that uniquely identifies it amongst the handlers registered with this canvas.- Parameters:
handler- the handler (nullnot permitted).
-
removeAuxiliaryMouseHandler
Removes a handler from the list of auxiliary handlers.- Parameters:
handler- the handler (nullnot permitted).
-
clearLiveHandler
Clears the current live handler. This method is intended for use by the handlers themselves, you should not call it directly. -
draw
Draws the content of the canvas and updates therenderingInfoattribute with the latest rendering information. -
findDataArea
Returns the data area (the area inside the axes) for the plot or subplot.- Parameters:
point- the selection point (for subplot selection).- Returns:
- The data area.
-
isResizable
Returntrueto indicate the canvas is resizable.- Overrides:
isResizablein classjavafx.scene.Node- Returns:
true.
-
setTooltip
Sets the tooltip text, with the (x, y) location being used for the anchor. If the text isnull, no tooltip will be displayed. This method is intended for calling by theTooltipHandlerFXclass, you won't normally call it directly.- Parameters:
text- the text (nullpermitted).x- the x-coordinate of the mouse pointer.y- the y-coordinate of the mouse pointer.
-
handleScroll
Handles a scroll event by passing it on to the registered handlers.- Parameters:
e- the scroll event.
-
chartChanged
Receives a notification from the chart that it has been changed and responds by redrawing the chart entirely.- Specified by:
chartChangedin interfaceorg.jfree.chart.event.ChartChangeListener- Parameters:
event- event information.
-