Example #1
0
  /**
   * The graphical representation of a series.
   *
   * @param canvas the canvas to paint to
   * @param paint the paint to be used for drawing
   * @param points the array of points to be used for drawing the series
   * @param seriesRenderer the series renderer
   * @param yAxisValue the minimum value of the y axis
   * @param seriesIndex the index of the series currently being drawn
   * @param startIndex the start index of the rendering points
   */
  @Override
  public void drawSeries(
      Canvas canvas,
      Paint paint,
      List<Float> points,
      XYSeriesRenderer seriesRenderer,
      float yAxisValue,
      int seriesIndex,
      int startIndex) {
    int seriesNr = mDataset.getSeriesCount();
    int length = points.size();
    paint.setColor(seriesRenderer.getColor());
    paint.setStyle(Style.FILL);
    float halfDiffX = getHalfDiffX(points, length, seriesNr);
    for (int i = 0; i < length; i += 2) {
      float x = points.get(i);
      float y = points.get(i + 1);

      if (mType == Type.HEAPED && seriesIndex > 0) {
        float lastY = mPreviousSeriesPoints.get(i + 1);
        y = y + (lastY - yAxisValue);
        points.set(i + 1, y);
        drawBar(canvas, x, lastY, x, y, halfDiffX, seriesNr, seriesIndex, paint);
      } else {
        drawBar(canvas, x, yAxisValue, x, y, halfDiffX, seriesNr, seriesIndex, paint);
      }
    }
    paint.setColor(seriesRenderer.getColor());
    mPreviousSeriesPoints = points;
  }
Example #2
0
 /**
  * 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);
       }
     }
   }
 }