Search in sources :

Example 6 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class ColumnToBarTransformer method generateTransformedValuesBarChart.

/**
	 * Transforms an arraylist of Entry into a float array containing the x and
	 * y values transformed with all matrices for the BARCHART.
	 *
	 * @param entries
	 * @param dataSet the dataset index
	 * @return
	 */
public float[] generateTransformedValuesBarChart(ArrayList<? extends Entry> entries, int dataSet, BarData bd, float phaseY) {
    float[] valuePoints = new float[entries.size() * 2];
    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();
    for (int j = 0; j < valuePoints.length; j += 2) {
        int index = j / 2;
        Entry e = entries.get(index);
        //TODO: Need to find a better value than 1, should be dependant on yMax, I think
        float x = e.getVal() + 1;
        // calculate the y-position, depending on datasetcount
        float y = e.getXIndex() + (index * (setCount - 1)) + dataSet + 0.5f + space * index + space / 2f;
        valuePoints[j] = x;
        valuePoints[j + 1] = y;
    }
    pointValuesToPixel(valuePoints);
    return valuePoints;
}
Also used : Entry(com.github.mikephil.charting.data.Entry)

Example 7 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class Transformer method generateTransformedValuesLineScatter.

/**
     * Transforms an arraylist of Entry into a float array containing the x and
     * y values transformed with all matrices for the LINECHART or SCATTERCHART.
     * 
     * @param entries
     * @return
     */
public float[] generateTransformedValuesLineScatter(ArrayList<? extends Entry> entries, float phaseY) {
    float[] valuePoints = new float[entries.size() * 2];
    for (int j = 0; j < valuePoints.length; j += 2) {
        Entry e = entries.get(j / 2);
        if (e != null) {
            valuePoints[j] = e.getXIndex();
            valuePoints[j + 1] = e.getVal() * phaseY;
        }
    }
    pointValuesToPixel(valuePoints);
    return valuePoints;
}
Also used : Entry(com.github.mikephil.charting.data.Entry)

Example 8 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class Chart method drawMarkers.

/**
     * draws all MarkerViews on the highlighted positions
     */
protected void drawMarkers() {
    // if there is no marker view or drawing marker is disabled
    if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight())
        return;
    for (int i = 0; i < mIndicesToHightlight.length; i++) {
        int xIndex = mIndicesToHightlight[i].getXIndex();
        int dataSetIndex = mIndicesToHightlight[i].getDataSetIndex();
        if (xIndex <= mDeltaX && xIndex <= mDeltaX * mPhaseX) {
            Entry e = getEntryByDataSetIndex(xIndex, dataSetIndex);
            // make sure entry not null
            if (e == null)
                continue;
            float[] pos = getMarkerPosition(e, dataSetIndex);
            // check bounds
            if (pos[0] < mOffsetLeft || pos[0] > getWidth() - mOffsetRight || pos[1] < mOffsetTop || pos[1] > getHeight() - mOffsetBottom)
                continue;
            // callbacks to update the content
            mMarkerView.refreshContent(e, dataSetIndex);
            // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
            // MeasureSpec.UNSPECIFIED),
            // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
            // mMarkerView.getMeasuredHeight());
            // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
            mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), mMarkerView.getMeasuredHeight());
            if (pos[1] - mMarkerView.getHeight() <= 0) {
                float y = mMarkerView.getHeight() - pos[1];
                mMarkerView.draw(mDrawCanvas, pos[0], pos[1] + y);
            } else {
                mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
            }
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) Paint(android.graphics.Paint)

Example 9 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class Chart method getEntriesAtIndex.

/**
     * Get all Entry objects at the given index across all DataSets.
     * INFORMATION: This method does calculations at runtime. Do not over-use in
     * performance critical situations.
     *
     * @param xIndex
     * @return
     */
public ArrayList<Entry> getEntriesAtIndex(int xIndex) {
    ArrayList<Entry> vals = new ArrayList<Entry>();
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        DataSet<? extends Entry> set = mData.getDataSetByIndex(i);
        Entry e = set.getEntryForXIndex(xIndex);
        if (e != null) {
            vals.add(e);
        }
    }
    return vals;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint)

Example 10 with Entry

use of com.github.mikephil.charting.data.Entry in project carat by amplab.

the class LineChart method generateLinePath.

/**
     * Generates the path that is used for drawing a single line.
     * 
     * @param entries
     * @return
     */
private Path generateLinePath(ArrayList<Entry> entries) {
    Path line = new Path();
    line.moveTo(entries.get(0).getXIndex(), entries.get(0).getVal() * mPhaseY);
    // create a new path
    for (int x = 1; x < entries.size() * mPhaseX; x++) {
        Entry e = entries.get(x);
        line.lineTo(e.getXIndex(), e.getVal() * mPhaseY);
    }
    return line;
}
Also used : Path(android.graphics.Path) Entry(com.github.mikephil.charting.data.Entry) Paint(android.graphics.Paint)

Aggregations

Entry (com.github.mikephil.charting.data.Entry)83 ArrayList (java.util.ArrayList)34 Paint (android.graphics.Paint)27 LineData (com.github.mikephil.charting.data.LineData)20 LineDataSet (com.github.mikephil.charting.data.LineDataSet)19 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)17 BarEntry (com.github.mikephil.charting.data.BarEntry)13 ScatterDataSet (com.github.mikephil.charting.data.ScatterDataSet)10 Path (android.graphics.Path)7 PieEntry (com.github.mikephil.charting.data.PieEntry)7 IOException (java.io.IOException)6 PointF (android.graphics.PointF)5 CandleEntry (com.github.mikephil.charting.data.CandleEntry)5 PieDataSet (com.github.mikephil.charting.data.PieDataSet)5 ScatterData (com.github.mikephil.charting.data.ScatterData)5 Highlight (com.github.mikephil.charting.highlight.Highlight)5 Transformer (com.github.mikephil.charting.utils.Transformer)5 Test (org.junit.Test)5 MPPointF (com.github.mikephil.charting.utils.MPPointF)4 SuppressLint (android.annotation.SuppressLint)3