Class BarChart
- Direct Known Subclasses:
RangeBarChart
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 Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BarChart.TypeThe chart type.static final StringThe constant to identify this chart type. -
Constructor Summary
ConstructorsConstructorDescriptionBarChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type) Builds a new bar chart instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected ClickableArea[]clickableAreasForPoints(List<Float> points, List<Double> values, float yAxisValue, int seriesIndex, int startIndex) Returns the clickable areas for all passed pointsprotected voiddrawBar(Canvas canvas, float xMin, float yMin, float xMax, float yMax, float halfDiffX, int seriesNr, int seriesIndex, Paint paint) Draws a bar.protected voiddrawBar(Canvas canvas, float xMin, float yMin, float xMax, float yMax, int scale, int seriesIndex, Paint paint) Draws a bar.protected voiddrawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRenderer renderer, Paint paint, List<Float> points, int seriesIndex, int startIndex) The graphical representation of the series values as text.voiddrawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint) The graphical representation of the legend shape.voiddrawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) The graphical representation of a series.Returns the chart type identifier.protected floatReturns the value of a constant used to calculate the half-distance.doubleReturns the default axis minimum.protected intgetGradientPartialColor(int minColor, int maxColor, float fraction) protected floatgetHalfDiffX(List<Float> points, int length, int seriesNr) Calculates and returns the half-distance in the graphical representation of 2 consecutive points.intgetLegendShapeWidth(int seriesIndex) Returns the legend shape width.protected booleanReturns if the chart should display the null values.Methods inherited from class XYChart
draw, drawPoints, drawSeries, drawText, drawXLabels, drawXTextLabels, drawYLabels, getCalcRange, getDataset, getPointsChart, getRenderer, getScreenR, getSeriesAndPointForScreenCoordinate, getXLabels, getYLabels, isRenderPoints, setCalcRange, setDatasetRenderer, setScreenR, toRealPoint, toRealPoint, toScreenPoint, toScreenPointMethods inherited from class AbstractChart
calculateDrawPoints, drawBackground, drawLabel, drawLegend, drawPath, drawPath, drawString, getExceed, getLabel, getLegendSize, isNullValue, isVertical
-
Field Details
-
TYPE
-
mType
The chart type.
-
-
Constructor Details
-
BarChart
public BarChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type) Builds a new bar chart instance.
Parameters
-
dataset: the multiple series dataset -
renderer: the multiple series renderer -
type: the bar chart type
-
-
-
Method Details
-
clickableAreasForPoints
protected ClickableArea[] clickableAreasForPoints(List<Float> points, List<Double> values, float yAxisValue, int seriesIndex, int startIndex) Description copied from class:XYChartReturns the clickable areas for all passed points
Parameters
-
points: the array of points -
values: the array of values of each point -
yAxisValue: the minimum value of the y axis -
seriesIndex: the index of the series to which the points belong -
startIndex: the start index of the rendering points
Returns
an array of rectangles with the clickable area
- Specified by:
clickableAreasForPointsin classXYChart
-
-
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
-
canvas: the canvas to paint to -
paint: the paint to be used for drawing -
points: the array of points to be used for drawing the series -
seriesRenderer: the series renderer -
yAxisValue: the minimum value of the y axis -
seriesIndex: the index of the series currently being drawn -
startIndex: the start index of the rendering points
- Specified by:
drawSeriesin classXYChart
-
-
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
-
canvas: the canvas -
xMin: the X axis minimum -
yMin: the Y axis minimum -
xMax: the X axis maximum -
yMax: the Y axis maximum -
halfDiffX: half the size of a bar -
seriesNr: the total number of series -
seriesIndex: the current series index -
paint: 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
-
canvas: the canvas -
xMin: the X axis minimum -
yMin: the Y axis minimum -
xMax: the X axis maximum -
yMax: the Y axis maximum -
scale: the scale index -
seriesIndex: the current series index -
paint: 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
-
canvas: the canvas to paint to -
series: the series to be painted -
renderer: the series renderer -
paint: the paint to be used for drawing -
points: the array of points to be used for drawing the series -
seriesIndex: the index of the series currently being drawn -
startIndex: the start index of the rendering points
- Overrides:
drawChartValuesTextin classXYChart
-
-
getLegendShapeWidth
public int getLegendShapeWidth(int seriesIndex) Returns the legend shape width.
Parameters
seriesIndex: the series index
Returns
the legend shape width
- Specified by:
getLegendShapeWidthin classAbstractChart
-
drawLegendShape
public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint) The graphical representation of the legend shape.
Parameters
-
canvas: the canvas to paint to -
renderer: the series renderer -
x: the x value of the point the shape should be drawn at -
y: the y value of the point the shape should be drawn at -
seriesIndex: the series index -
paint: the paint to be used for drawing
- Specified by:
drawLegendShapein classAbstractChart
-
-
getHalfDiffX
-
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
- Overrides:
isRenderNullValuesin classXYChart
-
getDefaultMinimum
public double getDefaultMinimum()Returns the default axis minimum.
Returns
the default axis minimum
- Overrides:
getDefaultMinimumin classXYChart
-
getChartType
Returns the chart type identifier.
Returns
the chart type
- Specified by:
getChartTypein classXYChart
-