public class BarChart
- Object
- AbstractChart
- XYChart
- BarChart
Known subtypesRangeBarChart
Renders a bar chart based on an XYMultipleSeriesDataset.
Create an instance together with a matching XYMultipleSeriesRenderer
and wrap it in a com.codename1.charts.ChartComponent to display it in
the UI. A minimal setup looks like this:
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(mySeries);
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.addSeriesRenderer(new XYSeriesRenderer());
BarChart chart = new BarChart(dataset, renderer, BarChart.Type.DEFAULT);
Form form = new Form(new BorderLayout());
form.add(BorderLayout.CENTER, new ChartComponent(chart));
form.show();
The Type supplied to the constructor controls whether the bars are
rendered in their default style, stacked or heaped.
Nested types
enum BarChart.Type | The bar chart type enum. |
Fields
public static final String TYPE = "Bar" | The constant to identify this chart type. |
protected BarChart.Type mType | The chart type. |
Constructors
public BarChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type) | Builds a new bar chart instance. |
Methods
Inherited fields
Inherited methods
From XYChart
setDatasetRenderer, draw, getXLabels, getYLabels, getScreenR, setScreenR, drawSeries, drawPoints, drawText, drawXLabels, drawYLabels, drawXTextLabels, getRenderer, getDataset, getCalcRange, setCalcRange, toRealPoint, toScreenPoint, toRealPoint, toScreenPoint, getSeriesAndPointForScreenCoordinate, isRenderPoints, getPointsChart
Field details
TYPE
public static final String TYPE = "Bar"The constant to identify this chart type.
mType
protected BarChart.Type mTypeThe chart type.
Constructor details
BarChart
public BarChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type)Builds a new bar chart instance.
Parameters
datasetXYMultipleSeriesDataset- the multiple series dataset
rendererXYMultipleSeriesRenderer- the multiple series renderer
typeBarChart.Type- the bar chart type
Method details
clickableAreasForPoints
protected ClickableArea[] clickableAreasForPoints(List<Float> points, List<Double> values, float yAxisValue, int seriesIndex, int startIndex)Returns the clickable areas for all passed points
Parameters
pointsList<Float>- the array of points
valuesList<Double>- the array of values of each point
yAxisValuefloat- the minimum value of the y axis
seriesIndexint- the index of the series to which the points belong
startIndexint- the start index of the rendering points
Returns
an array of rectangles with the clickable area
drawSeries
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex)The graphical representation of a series.
Parameters
canvasCanvas- the canvas to paint to
paintPaint- the paint to be used for drawing
pointsList<Float>- the array of points to be used for drawing the series
seriesRendererXYSeriesRenderer- the series renderer
yAxisValuefloat- the minimum value of the y axis
seriesIndexint- the index of the series currently being drawn
startIndexint- the start index of the rendering points
drawBar
protected void drawBar(Canvas canvas, float xMin, float yMin, float xMax, float yMax, float halfDiffX, int seriesNr, int seriesIndex, Paint paint)Draws a bar.
Parameters
canvasCanvas- the canvas
xMinfloat- the X axis minimum
yMinfloat- the Y axis minimum
xMaxfloat- the X axis maximum
yMaxfloat- the Y axis maximum
halfDiffXfloat- half the size of a bar
seriesNrint- the total number of series
seriesIndexint- the current series index
paintPaint- the paint
drawBar
protected void drawBar(Canvas canvas, float xMin, float yMin, float xMax, float yMax, int scale, int seriesIndex, Paint paint)Draws a bar.
Parameters
canvasCanvas- the canvas
xMinfloat- the X axis minimum
yMinfloat- the Y axis minimum
xMaxfloat- the X axis maximum
yMaxfloat- the Y axis maximum
scaleint- the scale index
seriesIndexint- the current series index
paintPaint- the paint
getGradientPartialColor
protected int getGradientPartialColor(int minColor, int maxColor, float fraction)drawChartValuesText
protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRenderer renderer, Paint paint, List<Float> points, int seriesIndex, int startIndex)The graphical representation of the series values as text.
Parameters
canvasCanvas- the canvas to paint to
seriesXYSeries- the series to be painted
rendererXYSeriesRenderer- the series renderer
paintPaint- the paint to be used for drawing
pointsList<Float>- the array of points to be used for drawing the series
seriesIndexint- the index of the series currently being drawn
startIndexint- the start index of the rendering points
getLegendShapeWidth
public int getLegendShapeWidth(int seriesIndex)Returns the legend shape width.
Parameters
seriesIndexint- the series index
Returns
the legend shape width
drawLegendShape
public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint)The graphical representation of the legend shape.
Parameters
canvasCanvas- the canvas to paint to
rendererSimpleSeriesRenderer- the series renderer
xfloat- the x value of the point the shape should be drawn at
yfloat- the y value of the point the shape should be drawn at
seriesIndexint- the series index
paintPaint- the paint to be used for drawing
getHalfDiffX
protected float getHalfDiffX(List<Float> points, int length, int seriesNr)Calculates and returns the half-distance in the graphical representation of
2 consecutive points.
Parameters
pointsList<Float>- the points
lengthint- the points length
seriesNrint- the series number
Returns
the calculated half-distance value
getCoeficient
protected float getCoeficient()Returns the value of a constant used to calculate the half-distance.
Returns
the constant value
isRenderNullValues
protected boolean isRenderNullValues()Returns if the chart should display the null values.
Returns
if null values should be rendered
getDefaultMinimum
public double getDefaultMinimum()Returns the default axis minimum.
Returns
the default axis minimum
getChartType
public String getChartType()Returns the chart type identifier.
Returns
the chart type