Search in sources :

Example 6 with XYSeries

use of com.codename1.charts.models.XYSeries in project CodenameOne by codenameone.

the class XYChart method drawSeries.

/**
 * Draws the series.
 *
 * @param series the series
 * @param canvas the canvas
 * @param paint the paint object
 * @param pointsList the points to be rendered
 * @param seriesRenderer the series renderer
 * @param yAxisValue the y axis value in pixels
 * @param seriesIndex the series index
 * @param or the orientation
 * @param startIndex the start index of the rendering points
 */
protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List<Float> pointsList, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, int startIndex) {
    BasicStroke stroke = seriesRenderer.getStroke();
    int cap = paint.getStrokeCap();
    int join = paint.getStrokeJoin();
    float miter = paint.getStrokeMiter();
    // PathEffect pathEffect = paint.getPathEffect();
    Style style = paint.getStyle();
    if (stroke != null) {
        setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, paint);
    }
    // float[] points = MathHelper.getFloats(pointsList);
    drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
    drawPoints(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
    paint.setTextSize(seriesRenderer.getChartValuesTextSize());
    if (or == Orientation.HORIZONTAL) {
        paint.setTextAlign(Align.CENTER);
    } else {
        paint.setTextAlign(Align.LEFT);
    }
    if (seriesRenderer.isDisplayChartValues()) {
        paint.setTextAlign(seriesRenderer.getChartValuesTextAlign());
        drawChartValuesText(canvas, series, seriesRenderer, paint, pointsList, seriesIndex, startIndex);
    }
    if (stroke != null) {
        setStroke(cap, join, miter, style, paint);
    }
}
Also used : BasicStroke(com.codename1.charts.renderers.BasicStroke) Style(com.codename1.charts.compat.Paint.Style) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 7 with XYSeries

use of com.codename1.charts.models.XYSeries 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)

Example 8 with XYSeries

use of com.codename1.charts.models.XYSeries in project CodenameOne by codenameone.

the class XYMultiSeriesTransition method getBuffer.

/**
 * Gets the buffer/cache for values.  Values set in the buffer will be applied
 * to the target dataset when the transition takes place.
 * @return
 */
public XYMultipleSeriesDataset getBuffer() {
    if (datasetCache == null) {
        datasetCache = new XYMultipleSeriesDataset();
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            datasetCache.addSeries(new XYSeries(dataset.getSeriesAt(i).getTitle()));
        }
        seriesTransitions = new XYSeriesTransition[dataset.getSeries().length];
        int tlen = seriesTransitions.length;
        for (int i = 0; i < tlen; i++) {
            seriesTransitions[i] = new XYSeriesTransition(getChart(), dataset.getSeriesAt(i));
            seriesTransitions[i].setBuffer(datasetCache.getSeriesAt(i));
        }
    }
    return datasetCache;
}
Also used : XYSeries(com.codename1.charts.models.XYSeries) XYMultipleSeriesDataset(com.codename1.charts.models.XYMultipleSeriesDataset)

Aggregations

Paint (com.codename1.charts.compat.Paint)6 XYSeries (com.codename1.charts.models.XYSeries)4 Point (com.codename1.charts.models.Point)3 ArrayList (java.util.ArrayList)2 Style (com.codename1.charts.compat.Paint.Style)1 XYMultipleSeriesDataset (com.codename1.charts.models.XYMultipleSeriesDataset)1 BasicStroke (com.codename1.charts.renderers.BasicStroke)1 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)1 XYSeriesRenderer (com.codename1.charts.renderers.XYSeriesRenderer)1 Rectangle (com.codename1.ui.geom.Rectangle)1 Rectangle2D (com.codename1.ui.geom.Rectangle2D)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TimeZone (java.util.TimeZone)1