Search in sources :

Example 11 with XYSeriesRenderer

use of com.codename1.charts.renderers.XYSeriesRenderer in project CodenameOne by codenameone.

the class BarChart method drawChartValuesText.

/**
 * The graphical representation of the series values as text.
 *
 * @param canvas the canvas to paint to
 * @param series the series to be painted
 * @param renderer the series renderer
 * @param paint the paint to be used for drawing
 * @param points the array of points to be used for drawing the series
 * @param seriesIndex the index of the series currently being drawn
 * @param startIndex the start index of the rendering points
 */
protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRenderer renderer, Paint paint, List<Float> points, int seriesIndex, int startIndex) {
    int seriesNr = mDataset.getSeriesCount();
    int length = points.size();
    float halfDiffX = getHalfDiffX(points, length, seriesNr);
    for (int i = 0; i < length; i += 2) {
        int index = startIndex + i / 2;
        double value = series.getY(index);
        if (!isNullValue(value)) {
            float x = points.get(i);
            if (mType == Type.DEFAULT) {
                x += seriesIndex * 2 * halfDiffX - (seriesNr - 1.5f) * halfDiffX;
            }
            if (value >= 0) {
                drawText(canvas, getLabel(renderer.getChartValuesFormat(), value), x, points.get(i + 1) - renderer.getChartValuesSpacing(), paint, 0);
            } else {
                drawText(canvas, getLabel(renderer.getChartValuesFormat(), value), x, points.get(i + 1) + renderer.getChartValuesTextSize() + renderer.getChartValuesSpacing() - 3, paint, 0);
            }
        }
    }
}
Also used : Paint(com.codename1.charts.compat.Paint)

Aggregations

Paint (com.codename1.charts.compat.Paint)11 Point (com.codename1.charts.models.Point)4 ArrayList (java.util.ArrayList)2 Style (com.codename1.charts.compat.Paint.Style)1 XYSeries (com.codename1.charts.models.XYSeries)1 XYValueSeries (com.codename1.charts.models.XYValueSeries)1 BasicStroke (com.codename1.charts.renderers.BasicStroke)1 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)1 XYSeriesRenderer (com.codename1.charts.renderers.XYSeriesRenderer)1 FillOutsideLine (com.codename1.charts.renderers.XYSeriesRenderer.FillOutsideLine)1 Rectangle (com.codename1.ui.geom.Rectangle)1 Rectangle2D (com.codename1.ui.geom.Rectangle2D)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1