public abstract class AbstractChart

  1. Object
  2. AbstractChart

Known subtypesRoundChart, XYChart

An abstract class to be implemented by the chart rendering classes.

Constructors

public AbstractChart()

Methods

protected static float[] calculateDrawPoints(float p1x, float p1y, float p2x, float p2y, int screenHeight, int screenWidth)
public abstract void draw(Canvas canvas, int x, int y, int width, int height, Paint paint)The graphical representation of the chart.
protected void drawBackground(DefaultRenderer renderer, Canvas canvas, int x, int y, int width, int height, Paint paint, boolean newColor, int color)Draws the chart background.
protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate)Draws the chart legend.
protected void drawString(Canvas canvas, String text, float x, float y, Paint paint)Draw a multiple lines string.
protected boolean getExceed(float currentWidth, DefaultRenderer renderer, int right, int width)Calculates if the current width exceeds the total width.
public boolean isVertical(DefaultRenderer renderer)Checks if the current chart is rendered as vertical.
protected String getLabel(NumberFormat format, double label)Makes sure the fraction digit is not displayed, if not needed.
protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular)The graphical representation of a path.
protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular)The graphical representation of a path.
public abstract int getLegendShapeWidth(int seriesIndex)Returns the legend shape width.
public abstract void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint)The graphical representation of the legend shape.
protected int getLegendSize(DefaultRenderer renderer, int defaultHeight, float extraHeight)Calculates the current legend size.
protected void drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<Rectangle2D> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display)Draws a text label.
public boolean isNullValue(double value)
public SeriesSelection getSeriesAndPointForScreenCoordinate(Point screenPoint)Given screen coordinates, returns the series and point indexes of a chart element.

Inherited methods

Constructor details

AbstractChart

public AbstractChart()

Method details

calculateDrawPoints

protected static float[] calculateDrawPoints(float p1x, float p1y, float p2x, float p2y, int screenHeight, int screenWidth)

draw

public abstract void draw(Canvas canvas, int x, int y, int width, int height, Paint paint)
The graphical representation of the chart.

Parameters

canvas Canvas
the canvas to paint to
x int
the top left x value of the view to draw to
y int
the top left y value of the view to draw to
width int
the width of the view to draw to
height int
the height of the view to draw to
paint Paint
the paint

drawBackground

protected void drawBackground(DefaultRenderer renderer, Canvas canvas, int x, int y, int width, int height, Paint paint, boolean newColor, int color)
Draws the chart background.

Parameters

renderer DefaultRenderer
the chart renderer
canvas Canvas
the canvas to paint to
x int
the top left x value of the view to draw to
y int
the top left y value of the view to draw to
width int
the width of the view to draw to
height int
the height of the view to draw to
paint Paint
the paint used for drawing
newColor boolean
if a new color is to be used
color int
the color to be used

drawLegend

protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate)
Draws the chart legend.

Parameters

canvas Canvas
the canvas to paint to
renderer DefaultRenderer
the series renderer
titles String[]
the titles to go to the legend
left int
the left X value of the area to draw to
right int
the right X value of the area to draw to
y int
the y value of the area to draw to
width int
the width of the area to draw to
height int
the height of the area to draw to
legendSize int
the legend size
paint Paint
the paint to be used for drawing
calculate boolean
if only calculating the legend size

Returns

the legend height

drawString

protected void drawString(Canvas canvas, String text, float x, float y, Paint paint)
Draw a multiple lines string.

Parameters

canvas Canvas
the canvas to paint to
text String
the text to be painted
x float
the x value of the area to draw to
y float
the y value of the area to draw to
paint Paint
the paint to be used for drawing

getExceed

protected boolean getExceed(float currentWidth, DefaultRenderer renderer, int right, int width)
Calculates if the current width exceeds the total width.

Parameters

currentWidth float
the current width
renderer DefaultRenderer
the renderer
right int
the right side pixel value
width int
the total width

Returns

if the current width exceeds the total width

isVertical

public boolean isVertical(DefaultRenderer renderer)
Checks if the current chart is rendered as vertical.

Parameters

renderer DefaultRenderer
the renderer

Returns

if the chart is rendered as a vertical one

getLabel

protected String getLabel(NumberFormat format, double label)
Makes sure the fraction digit is not displayed, if not needed.

Parameters

format NumberFormat
the number format for the label
label double
the input label value

Returns

the label without the useless fraction digit

drawPath

protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular)
The graphical representation of a path.

Parameters

canvas Canvas
the canvas to paint to
points List<Float>
the points that are contained in the path to paint
paint Paint
the paint to be used for painting
circular boolean
if the path ends with the start point

drawPath

protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular)
The graphical representation of a path.

Parameters

canvas Canvas
the canvas to paint to
points float[]
the points that are contained in the path to paint
paint Paint
the paint to be used for painting
circular boolean
if the path ends with the start point

getLegendShapeWidth

public abstract int getLegendShapeWidth(int seriesIndex)
Returns the legend shape width.

Parameters

seriesIndex int
the series index

Returns

the legend shape width

drawLegendShape

public abstract void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint)
The graphical representation of the legend shape.

Parameters

canvas Canvas
the canvas to paint to
renderer SimpleSeriesRenderer
the series renderer
x float
the x value of the point the shape should be drawn at
y float
the y value of the point the shape should be drawn at
seriesIndex int
the series index
paint Paint
the paint to be used for drawing

getLegendSize

protected int getLegendSize(DefaultRenderer renderer, int defaultHeight, float extraHeight)
Calculates the current legend size.

Parameters

renderer DefaultRenderer
the renderer
defaultHeight int
the default height
extraHeight float
the added extra height

Returns

the legend size

drawLabel

protected void drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<Rectangle2D> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display)
Draws a text label.

Parameters

canvas Canvas
the canvas
labelText String
the label text
renderer DefaultRenderer
the renderer
prevLabelsBounds List<Rectangle2D>
the previous rendered label bounds
centerX int
the round chart center on X axis
centerY int
the round chart center on Y axis
shortRadius float
the short radius for the round chart
longRadius float
the long radius for the round chart
currentAngle float
the current angle
angle float
the label extra angle
left int
the left side
right int
the right side
color int
the label color
paint Paint
the paint
line boolean
if a line to the label should be drawn
display boolean
display the label anyway

isNullValue

public boolean isNullValue(double value)

getSeriesAndPointForScreenCoordinate

public SeriesSelection getSeriesAndPointForScreenCoordinate(Point screenPoint)
Given screen coordinates, returns the series and point indexes of a chart element. If there is no chart element (line, point, bar, etc) at those coordinates, null is returned.

Returns

the series and point indexes