Skip to content

Modifying the Viewport

Philipp Jahoda edited this page Apr 5, 2015 · 18 revisions

This library has various methods for modifying the viewport (what is visible on the chart, aim of the view). Please note that these methods are only available for the LineChart, BarChart, ScatterChart and CandleStickChart.

Please note that all methods modifying the viewport need to be called on the Chart after setting data.

Restraining what's visible

  • setVisibleXRange(float xRange): Sets the size of the area (range on the x-axis) that should be maximum visible at once. If this is e.g. set to 10, no more than 10 values on the x-axis can be viewed at once without scrolling.
  • setVisibleYRange(float yRange, AxisDependency axis): Sets the size of the area (range on the y-axis) that should be maximum visible at once. You also need to provide the axis this constraint should apply to.
  • setViewPortOffsets(float left, float top, float right, float bottom): Sets custom offsets for the current ViewPort (the offsets on the sides of the actual chart window). Setting this will prevent the chart from automatically calculating it's offsets. Use resetViewPortOffsets() to undo this.
  • resetViewPortOffsets(): Resets all custom offsets set via setViewPortOffsets(...) method. Allows the chart to again calculate all offsets automatically.

Moving the view (where it is aimed)

  • fitScreen(): Resets all zooming and dragging and makes the chart fit exactly it's bounds (fully zoom out).
  • moveViewToX(float xIndex): Moves the left side (edge) of the current viewport to the specified x-index.
  • moveViewToY(float yValue, AxisDependency axis): Centers the viewport to the specified y-value on the provided y-axis (left or right).
  • moveViewTo(float xIndex, float yValue, AxisDependency axis): This will move the left side of the current viewport to the specified x-index on the x-axis, and center the viewport to the specified y-value on the provided y-axis (makes sense in combination with setVisibleXRange(...) and setVisibleYRange(...).
  • centerViewTo(int xIndex, float yValue, AxisDependency axis): This will move the center of the current viewport to the specified x-index and y-value (makes sense in combination with setVisibleXRange(...) and setVisibleYRange(...).

Full example

chart.setData(...); // first set data

// now modify viewport
chart.setVisibleXRange(20); // allow 20 values to be displayed on the x-axis
chart.moveViewToX(10); // set the left edge of the chart to x-index 10

// refresh
chart.invalidate();

The documentation has moved.

Clone this wiki locally