Esempio n. 1
0
  /** Draws the x-labels of the chart. */
  private void drawXLabels() {

    if (!mDrawXLabels) return;

    mXLabelPaint.setTypeface(mXLabels.getTypeface());
    mXLabelPaint.setTextSize(mXLabels.getTextSize());
    mXLabelPaint.setColor(mXLabels.getTextColor());

    float sliceangle = getSliceAngle();

    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = getFactor();

    PointF c = getCenterOffsets();

    for (int i = 0; i < mCurrentData.getXValCount(); i++) {

      String text = mCurrentData.getXVals().get(i);

      float angle = (sliceangle * i + mRotationAngle) % 360f;

      PointF p = getPosition(c, mYChartMax * factor + mXLabels.mLabelWidth / 2f, angle);

      mDrawCanvas.drawText(text, p.x, p.y + mXLabels.mLabelHeight / 2f, mXLabelPaint);
    }
  }
Esempio n. 2
0
  /** setup the x-axis labels */
  private void prepareXLabels() {

    StringBuffer a = new StringBuffer();

    int max = (int) Math.round(mCurrentData.getXValAverageLength());

    for (int i = 0; i < max; i++) {
      a.append("h");
    }

    mXLabels.mLabelWidth = Utils.calcTextWidth(mXLabelPaint, a.toString());
    mXLabels.mLabelHeight = Utils.calcTextWidth(mXLabelPaint, "Q");
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_linechart);

    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);

    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

    mSeekBarX.setProgress(45);
    mSeekBarY.setProgress(100);

    mSeekBarY.setOnSeekBarChangeListener(this);
    mSeekBarX.setOnSeekBarChangeListener(this);

    mChartView = (ChartView) findViewById(R.id.chart1);
    mChart = (LineChart) mChartView.getChart();
    mChart.setOnChartValueSelectedListener(this);

    // if enabled, the chart will always start at zero on the y-axis
    mChart.setStartAtZero(true);

    // enable the drawing of values into the chart
    mChart.setDrawYValues(true);

    mChart.setDrawBorder(true);
    mChart.setBorderPositions(new BorderPosition[] {BorderPosition.BOTTOM});

    // no description text
    mChart.setDescription("");

    // invert the y-axis
    mChart.setInvertYAxisEnabled(true);

    // enable value highlighting
    mChart.setHighlightEnabled(true);

    // enable touch gestures
    mChart.setTouchEnabled(true);

    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(true);

    // set an alternative background color
    // mChart.setBackgroundColor(Color.GRAY);

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);

    // define an offset to change the original position of the marker
    // (optional)
    mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());

    // set the marker to the chart
    mChart.setMarkerView(mv);

    // enable/disable highlight indicators (the lines that indicate the
    // highlighted Entry)
    mChart.setHighlightIndicatorEnabled(false);

    XLabels xl = mChart.getXLabels();
    xl.setAvoidFirstLastClipping(true);

    // add data
    setData(25, 50);

    // // restrain the maximum scale-out factor
    // mChart.setScaleMinima(3f, 3f);
    //
    // // center the view to a specific position inside the chart
    // mChart.centerViewPort(10, 50);

    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();

    // modify the legend ...
    // l.setPosition(LegendPosition.LEFT_OF_CHART);
    l.setForm(LegendForm.LINE);

    // dont forget to refresh the drawing
    mChartView.invalidate();
  }