### Fig Syntax Example
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
Example of using Fig Syntax directly within a Plot's XML.
```xml
androidPlot.title="My Plot"
```
--------------------------------
### Activity XML Layout
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
Create a layout file with an XYPlot view.
```xml
```
--------------------------------
### Proguard Rules
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
Add this to your proguard-rules.pro file if you are using Proguard obfuscation.
```proguard
-keep class com.androidplot.** { *; }
```
--------------------------------
### ProGuard Configuration Example
Source: https://github.com/halfhp/androidplot/blob/master/demoapp/proguard-project.txt
Example of ProGuard configuration directives, including assuming no side effects for logging methods.
```proguard
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
```
--------------------------------
### RecyclerView Example
Source: https://github.com/halfhp/androidplot/blob/master/docs/release_notes.md
This note indicates that a RecyclerView example was added to the demo app in version 1.5.9.
--------------------------------
### Line and Point Formatter with Labels 1
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
XML configuration for a line and point formatter with labels.
```xml
```
--------------------------------
### Gradle Dependency
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
Add the Androidplot core dependency to your build.gradle file.
```groovy
dependencies {
implementation "com.androidplot:androidplot-core:1.5.11"
}
```
--------------------------------
### Line and Point Formatter with Labels 2
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
XML configuration for a second line and point formatter with labels.
```xml
```
--------------------------------
### Programmatic Formatter Initialization
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
This code snippet shows an alternative to XML configuration for LineAndPointFormatter, demonstrating how to initialize it directly in Java.
```java
LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.RED, Color.GREEN, Color.BLUE, null);
```
--------------------------------
### Using CandlestickSeries and CandlestickMaker
Source: https://github.com/halfhp/androidplot/blob/master/docs/candlestick.md
Example demonstrating how to use CandlestickSeries and CandlestickMaker to add a candlestick chart to an XYPlot.
```java
CandlestickSeries candlestickSeries = new CandlestickSeries(
new CandlestickSeries.Item(1, 10, 2, 9),
new CandlestickSeries.Item(4, 18, 6, 5),
new CandlestickSeries.Item(3, 11, 5, 10),
new CandlestickSeries.Item(2, 17, 2, 15),
new CandlestickSeries.Item(6, 11, 11, 7),
new CandlestickSeries.Item(8, 16, 10, 15));
CandlestickFormatter formatter = new CandlestickFormatter();
// add the candlestick series data to the plot:
CandlestickMaker.make(plot, formatter, candlestickSeries);
```
--------------------------------
### Absolute Sizing
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Example of setting both height and width of a widget using absolute pixel values.
```xml
ap:graphHeightMode="absolute"
ap:graphHeight="100dp"
ap:graphWidthMode="absolute"
ap:graphWidth="100dp"
```
```java
plot.getGraph().setSize(new Size(
PixelUtils.dpToPix(100), SizeMode.ABSOLUTE,
PixelUtils.dpToPix(100), SizeMode.ABSOLUTE));
```
--------------------------------
### LineLabelStyle - Get Style
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of getting the style for the left edge line labels.
```java
plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.LEFT);
```
--------------------------------
### Simple XYPlot Activity
Source: https://github.com/halfhp/androidplot/blob/master/docs/quickstart.md
This Java code demonstrates how to create an Activity that displays an XYPlot with two series, using SimpleXYSeries and LineAndPointFormatter. It includes data population, formatter configuration with custom effects like dashed lines and smoothing, and custom domain label formatting.
```java
import android.app.Activity;
import android.graphics.*;
import android.os.Bundle;
import com.androidplot.util.PixelUtils;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYSeries;
import com.androidplot.xy.*;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.util.*;
/**
* A simple XYPlot
*/
public class SimpleXYPlotActivity extends Activity {
private XYPlot plot;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_xy_plot_example);
// initialize our XYPlot reference:
plot = (XYPlot) findViewById(R.id.plot);
// create a couple arrays of y-values to plot:
final Number[] domainLabels = {1, 2, 3, 6, 7, 8, 9, 10, 13, 14};
Number[] series1Numbers = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};
Number[] series2Numbers = {5, 2, 10, 5, 20, 10, 40, 20, 80, 40};
// turn the above arrays into XYSeries':
// (Y_VALS_ONLY means use the element index as the x value)
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");
XYSeries series2 = new SimpleXYSeries(
Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");
// create formatters to use for drawing a series using LineAndPointRenderer
// and configure them from xml:
LineAndPointFormatter series1Format =
new LineAndPointFormatter(this, R.xml.line_point_formatter_with_labels);
LineAndPointFormatter series2Format =
new LineAndPointFormatter(this, R.xml.line_point_formatter_with_labels_2);
// add an "dash" effect to the series2 line:
series2Format.getLinePaint().setPathEffect(new DashPathEffect(new float[] {
// always use DP when specifying pixel sizes, to keep things consistent across devices:
PixelUtils.dpToPix(20),
PixelUtils.dpToPix(15)}, 0));
// just for fun, add some smoothing to the lines:
// see: http://androidplot.com/smooth-curves-and-androidplot/
series1Format.setInterpolationParams(
new CatmullRomInterpolator.Params(10, CatmullRomInterpolator.Type.Centripetal));
series2Format.setInterpolationParams(
new CatmullRomInterpolator.Params(10, CatmullRomInterpolator.Type.Centripetal));
// add a new series' to the xyplot:
plot.addSeries(series1, series1Format);
plot.addSeries(series2, series2Format);
plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).setFormat(new Format() {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
int i = Math.round(((Number) obj).floatValue());
return toAppendTo.append(domainLabels[i]);
}
@Override
public Object parseObject(String source, ParsePosition pos) {
return null;
}
});
}
}
```
--------------------------------
### Using the custom renderer
Source: https://github.com/halfhp/androidplot/blob/master/docs/custom_renderer.md
Example of how to use the new custom renderer by adding a series to a plot using RoundedBarFormatter.
```java
plot.addSeries(series1, new RoundedBarFormatter(Color.RED));
plot.addSeries(series2, new RoundedBarFormatter(Color.BLUE));
```
--------------------------------
### Using FastLineAndPointRenderer for Dynamic Data
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of using FastLineAndPointRenderer for plotting large amounts of dynamic data.
```java
plot.addSeries(azimuthHistorySeries,
new FastLineAndPointRenderer.Formatter(
Color.rgb(100, 100, 200), null, null, null));
```
--------------------------------
### Absolute Width, Relative Height Sizing
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Example of setting absolute width and relative height for a widget.
```xml
ap:graphHeightMode="relative"
ap:graphHeight="1.0"
ap:graphWidthMode="absolute"
ap:graphWidth="100dp"
```
```java
plot.getGraph().setSize(new Size(
1.0f, SizeMode.RELATIVE,
PixelUtils.dpToPix(100), SizeMode.ABSOLUTE));
```
--------------------------------
### Extent: Setting Start Degrees and Extent Degrees
Source: https://github.com/halfhp/androidplot/blob/master/docs/piechart.md
Sets the starting degrees and the extent degrees to define the portion of the pie that represents 100%.
```java
// start the first segment at 5 degrees;
pie.getRenderer(PieRenderer.class).setStartDegs(165);
pie.getRenderer(PieRenderer.class).setExtentDegs(150);
```
--------------------------------
### Absolute Width, Absolute Height Sizing
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Example of setting absolute width and height with different pixel values.
```xml
ap:graphHeightMode="absolute"
ap:graphHeight="150dp"
ap:graphWidthMode="absolute"
ap:graphWidth="100dp"
```
```java
plot.getGraph().setSize(new Size(
PixelUtils.dpToPix(150), SizeMode.ABSOLUTE,
PixelUtils.dpToPix(100), SizeMode.ABSOLUTE));
```
--------------------------------
### Customizing Point Labeler
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of setting a custom PointLabeler to control which points are labeled and how.
```java
formatter.setPointLabeler(new PointLabeler() {
@Override
public String getLabel(XYSeries series, int index) {
// draw labels on even indexes only:
if(index % 2 == 0) {
return "Y=" + series.getY(index).doubleValue();
}
return null;
}
});
```
--------------------------------
### Line Label Insets
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Examples of setting line label insets using XML and Java.
```xml
ap:lineLabelInsetLeft="-5dp"
```
```java
plot.getGraph().getLineLabelInsets().setLeft(PixelUtils.dpToPix(-5));
```
--------------------------------
### Relative Width, Absolute Height Sizing
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Example of setting relative width and absolute height for a widget.
```xml
ap:graphHeightMode="absolute"
ap:graphHeight="100dp"
ap:graphWidthMode="relative"
ap:graphWidth="0.75"
```
```java
plot.getGraph().setSize(new Size(
PixelUtils.dpToPix(100), SizeMode.ABSOLUTE,
0.75f, SizeMode.RELATIVE));
```
--------------------------------
### Fill Width, Fill Height Sizing
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Example of using FILL mode for both width and height to make a widget fill available space after subtracting offsets.
```xml
ap:graphHeightMode="fill"
ap:graphHeight="50dp"
ap:graphWidthMode="fill"
ap:graphWidth="50dp"
```
```java
plot.getGraph().setSize(new Size(
PixelUtils.dpToPix(50), SizeMode.FILL,
PixelUtils.dpToPix(50), SizeMode.FILL));
```
--------------------------------
### SimpleXYSeries - Y_VALS_ONLY
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of creating a SimpleXYSeries with only y-values, where x-values are implicitly generated.
```java
Number[] yVals = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(yVals), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "my series");
```
--------------------------------
### SimpleXYSeries - XY_VALS_INTERLEAVED
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of creating a SimpleXYSeries with interleaved x and y values.
```java
Number[] yVals = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(yVals), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, "my series");
```
--------------------------------
### Segment Orientation: Setting Start Degrees
Source: https://github.com/halfhp/androidplot/blob/master/docs/piechart.md
Sets the starting degree for drawing segments, affecting their orientation.
```java
pie.getRenderer(PieRenderer.class).setStartDegs(90);
```
--------------------------------
### Example XYSeries
Source: https://github.com/halfhp/androidplot/blob/master/docs/barchart.md
To model this in Androidplot, create two instances of XYSeries; one for wins and one for losses, each with exactly 12 elements (one for each day of the month):
```java
XYSeries wins = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "wins", 3, 4, 5, 3, 2, 3, 5, 6, 2, 1, 3, 1);
XYSeries losses = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "losses", 0, 1, 1, 0, 1, 0, 0, 0, 2, 1, 0, 1);
```
--------------------------------
### Enabling Line Labels
Source: https://github.com/halfhp/androidplot/blob/master/docs/attrs.md
Example of how to enable line labels on specific edges of the graph.
```xml
ap:lineLabels="left|bottom"
```
--------------------------------
### DynamicTableModel Example
Source: https://github.com/halfhp/androidplot/blob/master/docs/legend.md
Configures the legend to use a DynamicTableModel with 2 rows and 2 columns, using ROW_MAJOR ordering.
```java
plot.getLegend().setTableModel(new DynamicTableModel(2, 2, TableOrder.ROW_MAJOR));
```
--------------------------------
### LineLabelRenderer - Custom Renderer
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of setting a custom line label renderer for the left edge.
```java
plot.getGraph().setLineLabelRenderer(XYGraphWidget.Edge.LEFT, customLineLabelRenderer);
```
--------------------------------
### SimpleXYSeries - Separate X and Y lists
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of creating a SimpleXYSeries using separate lists for x and y values.
```java
Number[] xVals = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};
Number[] yVals = {5, 2, 10, 5, 20, 10, 40, 20, 80, 40};
XYSeries series = new SimpleXYSeries(xVals, yVals, "my series");
```
--------------------------------
### Saving & Restoring PanZoom State - Save
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of saving the current pan/zoom state in an Activity.
```java
// save the current pan/zoom state
@Override
public void onSaveInstanceState(Bundle bundle) {
bundle.putSerializable("pan-zoom-state", panZoom.getState());
}
```
--------------------------------
### Pan & Zoom - Attach Default
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of enabling default pan/zoom behavior on an XYPlot instance.
```java
PanZoom.attach(plot);
```
--------------------------------
### Saving & Restoring PanZoom State - Restore
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of restoring a previously saved pan/zoom state in an Activity.
```java
// restore the previously saved pan/zoom state
@Override
public void onRestoreInstanceState(Bundle bundle) {
PanZoom.State state = (PanZoom.State) bundle.getSerializable("pan-zoom-state");
panZoom.setState(state);
plot.redraw();
}
```
--------------------------------
### Plot Listener for Synchronization
Source: https://github.com/halfhp/androidplot/blob/master/docs/dynamicdata.md
Example of using a PlotListener to synchronize data model changes with Androidplot's rendering loop.
```java
plot.addListener(new PlotListener() {
@Override
public void onBeforeDraw(Plot source, Canvas canvas) {
// write-lock each active series for writes
}
@Override
public void onAfterDraw(Plot source, Canvas canvas) {
// unlock any locked series
}
});
```
--------------------------------
### Registering a Series with a Formatter
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of how to add a new series to an XYPlot using a specific renderer's formatter.
```java
LineAndPointFormatter format = new LineAndPointFormatter();
plot.addSeries(series, format);
```
--------------------------------
### Dual Axis Labels - Enabling Edges
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Examples of enabling line labels on different edges of the graph using XML and Java.
```xml
ap:lineLabels="left|bottom|right"
```
```java
plot.getGraph().setLineLabelEdges(
XYGraphWidget.Edge.BOTTOM,
XYGraphWidget.Edge.LEFT,
XYGraphWidget.Edge.RIGHT);
```
--------------------------------
### Sampling XYSeries data
Source: https://github.com/halfhp/androidplot/blob/master/docs/advanced_xy_plot.md
Example of sampling a large XYSeries into a smaller one with a fixed size to improve rendering performance.
```java
XYSeries originalSeries = ...;
EditableXYSeries sampledSeries = new FixedSizeEditableXYSeries(
originalSeries.getTitle(), 200);
Sampler sampler = ...
new LTTBSampler().run(originalSeries, sampledSeries);
```
--------------------------------
### Candlestick Data Values
Source: https://github.com/halfhp/androidplot/blob/master/docs/candlestick.md
Example of raw data arrays for high, low, open, and close values used in candlestick charts.
```java
Number[] highVals = new Number[] {12, 10, 15, 8, 7};
Number[] lowVals = new Number[] {3, 1, 5, 0, 2};
Number[] openVals = new Number[] {5, 2, 7, 5, 3};
Number[] closeVals = new Number[] {7, 9, 6, 0, 4};
```
--------------------------------
### FixedTableModel Example
Source: https://github.com/halfhp/androidplot/blob/master/docs/legend.md
Configures the legend to use a FixedTableModel with cells of 300 pixels width and 100 pixels height, using COLUMN_MAJOR ordering.
```java
plot.getLegend().setTableModel(new FixedTableModel(PixelUtils.dpToPix(300),
PixelUtils.dpToPix(100), TableOrder.COLUMN_MAJOR));
```
--------------------------------
### Getting the BarRenderer Instance
Source: https://github.com/halfhp/androidplot/blob/master/docs/barchart.md
Many of the topics below require access to the BarRenderer instance to be set. Each instance of XYPlot contains it's own unique Renderer instances. To retrieve the BarRenderer instance from an XYPlot:
```java
BarRenderer renderer = plot.getRenderer(BarRenderer.class);
```
--------------------------------
### Basic Usage
Source: https://github.com/halfhp/androidplot/blob/master/docs/bubblechart.md
Or it's equivalent four argument counterpart:
```java
BubbleSeries bubbleSeries = new BubbleSeries(
Arrays.asList(new Number[]{0, 1, 2, 3, 4}), // xCoordinate
Arrays.asList(new Number[]{3, 5, 2, 3, 6}), // yCoordinate
Arrays.asList(new Number[]{1, 5, 2, 2, 3}), // zVal (corresponds to radius)
"s1");
```
--------------------------------
### Basic Usage
Source: https://github.com/halfhp/androidplot/blob/master/docs/bubblechart.md
Next, create a Formatter defining the fill and outline colors of the bubbles:
```java
// draw bubbles with a green fill and white outline:
BubbleFormatter formatter = new BubbleFormatter(Color.GREEN, Color.WHITE)
```
--------------------------------
### Basic Usage
Source: https://github.com/halfhp/androidplot/blob/master/docs/bubblechart.md
Using the implicit iVal for x:
```java
BubbleSeries series1 = new BubbleSeries(
Arrays.asList(new Number[]{3, 5, 2, 3, 6}), // xCoordinate
Arrays.asList(new Number[]{1, 5, 2, 2, 3}), "s1"); // yCoordinate
```
--------------------------------
### Pan & Zoom - Attach Horizontal Only
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of enabling pan and zoom (stretch) on the horizontal axis only.
```java
PanZoom.attach(plot, PanZoom.Pan.HORIZONTAL, PanZoom.Zoom.STRETCH_HORIZONTAL);
```
--------------------------------
### Basic Usage
Source: https://github.com/halfhp/androidplot/blob/master/docs/bubblechart.md
Finally, add the BubbleSeries to our plot as you would any other XYSeries instance:
```java
plot.addSeries(bubbleSeries, formatter);
```
--------------------------------
### Build Androidplot Project
Source: https://github.com/halfhp/androidplot/blob/master/docs/contributing.md
Command to perform a full build of the Androidplot project using Gradle.
```bash
./gradlew test assemble
```
--------------------------------
### Apache License Boilerplate
Source: https://github.com/halfhp/androidplot/blob/master/LICENSE.md
This is the standard boilerplate notice for applying the Apache License to a work.
```text
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
--------------------------------
### Absolute Positioning from Left/Top
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Demonstrates positioning an XYGraphWidget at the top-left corner with absolute positioning.
```xml
ap:graphAnchor="right_bottom"
ap:graphHorizontalPositioning="absolute_from_left"
ap:graphHorizontalPosition="0dp"
ap:graphVerticalPositioning="relative_from_top"
ap:graphVerticalPosition="0dp"
```
```java
plot.getGraph().position(
0, HorizontalPositioning.ABSOLUTE_FROM_LEFT,
0, VerticalPositioning.RELATIVE_TO_TOP);
```
--------------------------------
### AnimatedXYPlotActivity
Source: https://github.com/halfhp/androidplot/blob/master/docs/release_notes.md
This note mentions the addition of AnimatedXYPlotActivity demonstrating the use of ScalingXYSeries for animated intros.
```java
package com.androidplot.demos;
import com.androidplot.xy.XYSeries;
public class AnimatedXYPlotActivity {
// ... other code ...
ScalingXYSeries scalingSeries = new ScalingXYSeries(originalSeries);
// ... other code ...
}
```
--------------------------------
### Clone Androidplot Repository
Source: https://github.com/halfhp/androidplot/blob/master/docs/contributing.md
Command to clone the Androidplot project from GitHub.
```bash
git clone https://github.com/halfhp/androidplot.git
```
--------------------------------
### Enabling ZoomEstimator with SampledXYSeries
Source: https://github.com/halfhp/androidplot/blob/master/docs/advanced_xy_plot.md
Shows how to enable automatic sampling level selection based on visible boundaries using ZoomEstimator.
```java
// enable autoselect of sampling level based on visible boundaries:
plot.getRegistry().setEstimator(new ZoomEstimator());
```
--------------------------------
### Enable Background Rendering via XML
Source: https://github.com/halfhp/androidplot/blob/master/docs/dynamicdata.md
Enables background rendering mode for the plot using XML attributes.
```xml
ap:renderMode="use_background_thread"
```
--------------------------------
### SampledXYSeries Basic Usage
Source: https://github.com/halfhp/androidplot/blob/master/docs/advanced_xy_plot.md
Demonstrates how to wrap an existing XYSeries in a SampledXYSeries for faster rendering with stepped resolutions.
```java
XYSeries series = ... // instantiate an XYSeries however you want here
// wrap our series in a SampledXYSeries with a threshold of 1000:
SampledXYSeries sampledSeries =
new SampledXYSeries(series, OrderedXYSeries.XOrder.ASCENDING, 2,100);
// add the SampledXYSeries instance to the plot:
plot.addSeries(sampledSeries, formatter);
```
--------------------------------
### Pan & Zoom - Set Outer Limits
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of setting the plot's outer limits to cap pan/zoom.
```java
// cap pan/zoom limits for panning and zooming to a 100x100 space:
plot.getOuterLimits().set(0, 100, 0, 100);
```
--------------------------------
### Dual Axis Labels - Custom Formatter
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Example of setting a custom formatter for right edge line labels.
```java
plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.RIGHT).setFormat(new Format() {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
// obj contains the raw Number value representing the position of the label being drawn.
// customize the labeling however you want here:
int i = Math.round(((Number) obj).floatValue());
return toAppendTo.append(i + " thingies");
}
@Override
public Object parseObject(String source, ParsePosition pos) {
// unused
return null;
}
});
```
--------------------------------
### Enable Background Rendering Programmatically
Source: https://github.com/halfhp/androidplot/blob/master/docs/dynamicdata.md
Enables background rendering mode for the plot via Java code.
```java
plot.setRenderMode(Plot.RenderMode.USE_BACKGROUND_THREAD);
```
--------------------------------
### Basic Usage
Source: https://github.com/halfhp/androidplot/blob/master/docs/barchart.md
Rendering an XYSeries as a bar chart is as simple as adding the series to an XYPlot with an instance of BarFormatter.
```java
BarFormatter bf = new BarFormatter(Color.RED, Color.WHITE);
plot.addSeries(series, bf);
```
--------------------------------
### Absolute Positioning from Center
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Illustrates centering an XYGraphWidget using absolute positioning.
```xml
ap:graphAnchor="center"
ap:graphHorizontalPositioning="absolute_from_center"
ap:graphHorizontalPosition="0dp"
ap:graphVerticalPositioning="absolute_from_center"
ap:graphVerticalPosition="0dp"
```
```java
plot.getGraph().position(
0, HorizontalPositioning.ABSOLUTE_FROM_CENTER,
0, VerticalPositioning.ABSOLUTE_FROM_CENTER);
```
--------------------------------
### Basic Usage: Creating a Segment
Source: https://github.com/halfhp/androidplot/blob/master/docs/piechart.md
Instantiates a new Segment with a label and a value.
```java
Segment segment = new Segment("my segment", 10);
```
--------------------------------
### Absolute Positioning from Right/Bottom
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Illustrates positioning an XYGraphWidget at the bottom-right corner with absolute positioning.
```xml
ap:graphAnchor="right_bottom"
ap:graphHorizontalPositioning="absolute_from_right"
ap:graphHorizontalPosition="0dp"
ap:graphVerticalPositioning="relative_from_bottom"
ap:graphVerticalPosition="0dp"
```
```java
plot.getGraph().position(
0, HorizontalPositioning.ABSOLUTE_FROM_RIGHT,
0, VerticalPositioning.RELATIVE_TO_BOTTOM);
```
--------------------------------
### BubbleScaleMode
Source: https://github.com/halfhp/androidplot/blob/master/docs/bubblechart.md
If you'd prefer to use a linear scale:
```java
plot.getRenderer(BubbleRenderer.class).setBubbleScaleMode(BubbleRenderer.BubbleScaleMode.LINEAR);
```
--------------------------------
### RoundedBarFormatter
Source: https://github.com/halfhp/androidplot/blob/master/docs/custom_renderer.md
The first step to creating a custom renderer is defining its Formatter. This class provides visual configuration and maps a series to a specific renderer type.
```java
class RoundedBarFormatter extends BarFormatter {
{
// for now we'll hardcode some formatting values.
// a real implementation would probably provide a constructor instead
getBorderPaint().setColor(Color.WHITE);
getFillPaint().setColor(Color.RED);
}
@Override
public Class getRendererClass() {
return RoundedBarRenderer.class;
}
@Override
public RoundedBarRenderer doGetRendererInstance(XYPlot xyPlot) {
return new RoundedBarRenderer(xyPlot);
}
}
```
--------------------------------
### Basic Usage: Creating a SegmentFormatter
Source: https://github.com/halfhp/androidplot/blob/master/docs/piechart.md
Instantiates a new SegmentFormatter with a specified color.
```java
SegmentFormatter formatter = new SegmentFormatter(Color.RED);
```
--------------------------------
### Absolute Positioning with Offset
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Shows positioning an XYGraphWidget with an offset from the bottom-right corner.
```xml
ap:graphAnchor="right_bottom"
ap:graphHorizontalPositioning="absolute_from_right"
ap:graphHorizontalPosition="10dp"
ap:graphVerticalPositioning="relative_from_bottom"
ap:graphVerticalPosition="10dp"
```
```java
plot.getGraph().position(
PixelUtils.dpToPix(10), HorizontalPositioning.ABSOLUTE_FROM_RIGHT,
PixelUtils.dpToPix(10), VerticalPositioning.RELATIVE_TO_BOTTOM);
```
--------------------------------
### Enabling Point Labels
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Code snippet demonstrating how to enable and customize point labels for a LineAndPointFormatter.
```java
PointLabelFormatter plf = new PointLabelFormatter();
plf.getTextPaint().setTextSize(PixelUtils.spToPix(12));
plf.getTextPaint().setColor(Color.RED);
lineAndPointFormatter.setPointLabelFormatter(plf);
```
--------------------------------
### Enable Markup Mode Programmatically
Source: https://github.com/halfhp/androidplot/blob/master/docs/plot_composition.md
Enables markup mode for a plot programmatically to visualize margins and padding.
```java
plot.setMarkupEnabled(true);
```
--------------------------------
### Graph Rotation in Java
Source: https://github.com/halfhp/androidplot/blob/master/docs/xyplot.md
Setting the graph rotation programmatically using Java.
```java
plot.getGraph().setRotation(Widget.Rotation.NINETY_DEGREES);
```
--------------------------------
### FastLineAndPointRenderer
Source: https://github.com/halfhp/androidplot/blob/master/docs/release_notes.md
Updated OrientationSensorExampleActivity to use FastLineAndPointRenderer.
```java
FastLineAndPointRenderer
```
--------------------------------
### RoundedBarRenderer
Source: https://github.com/halfhp/androidplot/blob/master/docs/custom_renderer.md
This class extends BarRenderer and provides the base for custom bar drawing behavior.
```java
class RoundedBarRenderer extends BarRenderer {
public RoundedBarRenderer(XYPlot plot) {
super(plot);
}
@Override
protected void drawBar(Canvas canvas, Bar bar, RectF rect) {
// TODO this is where we'll add our custom behavior
}
}
```
--------------------------------
### Draw Grid on Top
Source: https://github.com/halfhp/androidplot/blob/master/docs/release_notes.md
Added drawGridOnTop param to XYGraphWidget.
```java
drawGridOnTop param to XYGraphWidget; when set to true, grid lines will be drawn on top of rendered series data. (default is false)
```
--------------------------------
### Custom drawBar implementation
Source: https://github.com/halfhp/androidplot/blob/master/docs/custom_renderer.md
This method overrides the default drawBar behavior to draw bars with rounded edges using a Path.
```java
@Override
protected void drawBar(Canvas canvas, Bar bar, RectF rect) {
// skip nulls:
if(bar.getY() == null) {
return;
}
RoundedBarFormatter formatter = getFormatter(bar.i, bar.series);
if(formatter == null) {
formatter = bar.formatter;
}
// don't need to draw if the bar lacks height or width:
if (rect.height() > 0 && rect.width() > 0) {
final Path path = new Path();
final float arcHeightPx = 20;
final float adjustedTop = rect.top + arcHeightPx;
final RectF cap = new RectF(rect.left, rect.top, rect.right,rect.top + 2 * arcHeightPx);
// start at bottom-left and move clock-wise around the shape:
path.moveTo(rect.left, rect.bottom);
path.lineTo(rect.left, adjustedTop);
path.arcTo(cap, 180, 180, false);
path.lineTo(rect.right, rect.bottom);
path.close();
canvas.drawPath(path, formatter.getFillPaint());
canvas.drawPath(path, formatter.getBorderPaint());
}
}
```
--------------------------------
### PanZoom Interface Change
Source: https://github.com/halfhp/androidplot/blob/master/docs/release_notes.md
Note about potential code updates required for PanZoom due to interface changes.
```text
PanZoom performance enhancements & bug fixes. If you're currently using PanZoom you'll likely need to
update your code as the interface has slightly changed.
```