public class

Crosshair

extends Object
java.lang.Object
   ↳ com.shinobicontrols.charts.Crosshair

Class Overview

The Crosshair provides a small circle target with lines that extend to the axis. This is accompanied by a tooltip which displays the X and Y values the crosshair is currently focused on.

The crosshair is enabled with a tap-and-hold gesture and will lock to the nearest series to pan through the values. On a LineSeries the values will be interpolated between data points, on all other series types the crosshair will jump from data point to data point. Interpolation for a line series can be switched off using the setLineSeriesInterpolationEnabled(boolean) method.

In order for a crosshair to be displayed on a chart series, the series must enable it by calling setCrosshairEnabled(boolean) with true. This defaults to false, so you will need to call this method on each series in your chart.

Summary

Nested Classes
enum Crosshair.DrawLinesBehavior The behavior of the crosshair with respect to how it draws its lines. 
enum Crosshair.Mode The behavior mode for the crosshair when tracking series. 
enum Crosshair.OutOfRangeBehavior The behavior of the crosshair when it is moved out of the visible range. 
Public Methods
void enableTooltip(boolean tooltipEnabled)
Sets whether a Tooltip should be displayed when the user shows the Crosshair with a long press gesture.
Crosshair.DrawLinesBehavior getDrawLinesBehavior()
Data<?, ?> getFocus()
Returns a Data containing the focus X and Y values for this crosshair, in data terms, used for drawing.
Crosshair.Mode getMode()
Crosshair.OutOfRangeBehavior getOutOfRangeBehavior()
float getPixelXValue()
Returns this crosshair's current X position in pixels relative to the chart.
float getPixelYValue()
Returns this crosshair's current Y position in pixels relative to the chart.
CrosshairStyle getStyle()
Returns the CrosshairStyle object that manages the look of the crosshair.
Tooltip getTooltip()
Returns the tooltip which presents values to the user for the point the crosshair is currently focused on.
CartesianSeries<?> getTrackedSeries()
Returns the series this crosshair is currently tracking.
boolean isActive()
Whether this crosshair is currently active.
boolean isLineSeriesInterpolationEnabled()
Whether, when tracking a line series, the crosshair moves smoothly or jumps between data points as it is panned.
boolean isShown()
Whether this crosshair is currently shown on the plot area.
boolean isTooltipEnabled()
Returns whether a Tooltip should be displayed when the user shows the Crosshair with a long press gesture.
void setDrawLinesBehavior(Crosshair.DrawLinesBehavior drawLinesBehavior)
Displays or hides the crosshair lines, depending on the setting.
void setFocus(Data<?, ?> focus)
Sets the focus X and Y value of this crosshair, in data terms, used for drawing.
void setLineSeriesInterpolationEnabled(boolean enabled)
If set to true the crosshair will move smoothly between points when tracking a line series.
void setMode(Crosshair.Mode mode)
Sets the mode of tracking behavior for the crosshair.
void setOutOfRangeBehavior(Crosshair.OutOfRangeBehavior outOfRangeBehavior)
Sets the behavior of the crosshair when it moves out of the currently displayed range.
void setStyle(CrosshairStyle style)
Sets the CrosshairStyle object that should manage the look of the crosshair.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void enableTooltip (boolean tooltipEnabled)

Sets whether a Tooltip should be displayed when the user shows the Crosshair with a long press gesture.

By default the tooltip is enabled for the crosshair.

Parameters
tooltipEnabled whether a Tooltip should be displayed when the user performs a long press gesture.

public Crosshair.DrawLinesBehavior getDrawLinesBehavior ()

public Data<?, ?> getFocus ()

Returns a Data containing the focus X and Y values for this crosshair, in data terms, used for drawing.

The crosshair does not know the types of the X and Y values so returns them each as an java.lang.Object. However, they will be of the corresponding type for the applicable axis and so can be safely cast e.g. for a NumberAxis the value can be cast to a java.lang.Double, for a DateTimeAxis the value can be cast to a java.util.Date.

Note that for a CategoryAxis, which is an extension of the NumberAxis, the returned X or Y value will be a Double. This number represents the index in the getCategories() list of the corresponding category String.

Returns
  • the focus X and Y values of this crosshair, in data terms, used for drawing

public Crosshair.Mode getMode ()

Returns
  • the Crosshair.Mode that controls the tracking behavior of the crosshair.

public Crosshair.OutOfRangeBehavior getOutOfRangeBehavior ()

Returns
  • the behavior of the crosshair when it is out of the current displayed range.

public float getPixelXValue ()

Returns this crosshair's current X position in pixels relative to the chart. This is a convenience method; the pixel position can also be obtained using the tracking point and the axes from the tracking series.

Returns
  • this crosshair's current X position in pixels relative to the chart

public float getPixelYValue ()

Returns this crosshair's current Y position in pixels relative to the chart. This is a convenience method; the pixel position can also be obtained using the tracking point and the axes from the tracking series.

Returns
  • this crosshair's current Y position in pixels relative to the chart

public CrosshairStyle getStyle ()

Returns the CrosshairStyle object that manages the look of the crosshair.

Returns
  • the style object that manages the look of the crosshair

public Tooltip getTooltip ()

Returns the tooltip which presents values to the user for the point the crosshair is currently focused on.

Returns
  • the tooltip which presents values from the current crosshair focus point

public CartesianSeries<?> getTrackedSeries ()

Returns the series this crosshair is currently tracking.

Returns
  • the series this crosshair is currently tracking

public boolean isActive ()

Whether this crosshair is currently active. The crosshair may still be active even if it is not currently shown on the plot area. For example, zooming the chart with the crosshair displayed may result in the crosshair being moved past the edge of the plot area. As it is still active a swipe gesture will move it back inside the plot area.

Returns
  • whether this crosshair is currently active

public boolean isLineSeriesInterpolationEnabled ()

Whether, when tracking a line series, the crosshair moves smoothly or jumps between data points as it is panned.

Returns
  • whether the crosshair moves smoothly between points when tracking a line series

public boolean isShown ()

Whether this crosshair is currently shown on the plot area.

Returns
  • whether the crosshair is currently shown on the plot area

public boolean isTooltipEnabled ()

Returns whether a Tooltip should be displayed when the user shows the Crosshair with a long press gesture.

By default the tooltip is enabled for the crosshair.

Returns
  • whether a Tooltip should be displayed when the user shows the Crosshair with a long press gesture.

public void setDrawLinesBehavior (Crosshair.DrawLinesBehavior drawLinesBehavior)

Displays or hides the crosshair lines, depending on the setting. ALWAYS will always display the lines, NEVER will never display the lines, SERIES_DEFAULT will display the lines according to the default value for the relevant series, false for all series except Line series.

Parameters
drawLinesBehavior the Crosshair.DrawLinesBehavior for the crosshair.

public void setFocus (Data<?, ?> focus)

Sets the focus X and Y value of this crosshair, in data terms, used for drawing.

The crosshair only tracks a series when an appropriate user gesture is performed. Without a tracked series focus is ignored as it is impossible to determine which axes the point refers to.

If the type of the X or Y value of focus is not compatible with the respective X and Y axes for the tracked series a java.lang.ClassCastException will be thrown. Similarly, if either value is null, or if focus itself is null, a java.lang.IllegalArgumentException will be thrown.

Parameters
focus the focus X and Y values of this crosshair, in data terms, used for drawing

public void setLineSeriesInterpolationEnabled (boolean enabled)

If set to true the crosshair will move smoothly between points when tracking a line series. Otherwise the crosshair will jump from point to point as it tracks.

By default, this property is set to true.

Parameters
enabled whether the crosshair should move smoothly between points when tracking a line series

public void setMode (Crosshair.Mode mode)

Sets the mode of tracking behavior for the crosshair. With SINGLE_SERIES, the crosshair remains on the same series while panning, jumping between the series' data points depending on which is closest. For FLOATING, the crosshair will jump to the closest data point on any series on the chart, potentially moving between series. If the series is a line series and setLineSeriesInterpolationEnabled(boolean) is true the crosshair will move smoothly between data points.

Parameters
mode the tracking behavior Crosshair.Mode to set on the crosshair

public void setOutOfRangeBehavior (Crosshair.OutOfRangeBehavior outOfRangeBehavior)

Sets the behavior of the crosshair when it moves out of the currently displayed range.

HIDE causes the crosshair to move out of the displayed range but continue to be active and track the series on the chart. Panning inside the displayed range, or moving the focus point back in by zooming out for example, will bring the crosshair back into view.

KEEP_AT_EDGE causes the crosshair (and its tooltip) to remain at the edge of the plot area until it is panned back, or the focus point is brought back, into the displayed range.

REMOVE will cause the crosshair to disappear and no longer be active, that is, it will no longer track a series. A long press gesture must be performed again to bring the crosshair up.

By default the crosshair's OutOfRangeBehavior is set to HIDE.

Parameters
outOfRangeBehavior the behavior to set on the crosshair when it is out of the current displayed range

public void setStyle (CrosshairStyle style)

Sets the CrosshairStyle object that should manage the look of the crosshair.

Parameters
style the style object that will manage the look of the crosshair
See Also