Search in sources :

Example 46 with Entry

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

the class Chart method highlightTouch.

/**
     * Highlights the value selected by touch gesture. Unlike
     * highlightValues(...), this generates a callback to the
     * OnChartValueSelectedListener.
     *
     * @param highs
     */
public void highlightTouch(Highlight high) {
    if (high == null)
        mIndicesToHightlight = null;
    else {
        // set the indices to highlight
        mIndicesToHightlight = new Highlight[] { high };
    }
    // redraw the chart
    invalidate();
    if (mSelectionListener != null) {
        if (!valuesToHighlight())
            mSelectionListener.onNothingSelected();
        else {
            Entry e = getEntryByDataSetIndex(high.getXIndex(), high.getDataSetIndex());
            // notify the listener
            mSelectionListener.onValueSelected(e, high.getDataSetIndex());
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry)

Example 47 with Entry

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

the class FileUtils method loadEntriesFromAssets.

/**
     * Loads an array of Entries from a textfile from the assets folder.
     * 
     * @param am
     * @param path the name of the file in the assets folder (+ path if needed)
     * @return
     */
public static ArrayList<Entry> loadEntriesFromAssets(AssetManager am, String path) {
    ArrayList<Entry> entries = new ArrayList<Entry>();
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(am.open(path), "UTF-8"));
        String line = reader.readLine();
        while (line != null) {
            // process line
            String[] split = line.split("#");
            if (split.length <= 2) {
                entries.add(new Entry(Float.parseFloat(split[0]), Integer.parseInt(split[1])));
            } else {
                float[] vals = new float[split.length - 1];
                for (int i = 0; i < vals.length; i++) {
                    vals[i] = Float.parseFloat(split[i]);
                }
                entries.add(new BarEntry(vals, Integer.parseInt(split[split.length - 1])));
            }
            line = reader.readLine();
        }
    } catch (IOException e) {
        Log.e(LOG, e.toString());
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                Log.e(LOG, e.toString());
            }
        }
    }
    return entries;
// String label = null;
// ArrayList<Entry> entries = new ArrayList<Entry>();
//
// BufferedReader reader = null;
// try {
// reader = new BufferedReader(
// new InputStreamReader(am.open(path), "UTF-8"));
//
// // do reading, usually loop until end of file reading
// label = reader.readLine();
// String line = reader.readLine();
//
// while (line != null) {
// // process line
// String[] split = line.split("#");
// entries.add(new Entry(Float.parseFloat(split[0]),
// Integer.parseInt(split[1])));
// line = reader.readLine();
// }
// } catch (IOException e) {
// Log.e(LOG, e.toString());
//
// } finally {
//
// if (reader != null) {
// try {
// reader.close();
// } catch (IOException e) {
// Log.e(LOG, e.toString());
// }
// }
// }
//
// DataSet ds = new DataSet(entries, label);
// return ds;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 48 with Entry

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

the class FileUtils method loadEntriesFromFile.

/**
     * Loads a an Array of Entries from a textfile from the sd-card.
     * 
     * @param path the name of the file on the sd-card (+ path if needed)
     * @return
     */
public static ArrayList<Entry> loadEntriesFromFile(String path) {
    File sdcard = Environment.getExternalStorageDirectory();
    // Get the text file
    File file = new File(sdcard, path);
    ArrayList<Entry> entries = new ArrayList<Entry>();
    try {
        @SuppressWarnings("resource") BufferedReader br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            String[] split = line.split("#");
            if (split.length <= 2) {
                entries.add(new Entry(Float.parseFloat(split[0]), Integer.parseInt(split[1])));
            } else {
                float[] vals = new float[split.length - 1];
                for (int i = 0; i < vals.length; i++) {
                    vals[i] = Float.parseFloat(split[i]);
                }
                entries.add(new BarEntry(vals, Integer.parseInt(split[split.length - 1])));
            }
        }
    } catch (IOException e) {
        Log.e(LOG, e.toString());
    }
    return entries;
// File sdcard = Environment.getExternalStorageDirectory();
//
// // Get the text file
// File file = new File(sdcard, path);
//
// ArrayList<Entry> entries = new ArrayList<Entry>();
// String label = "";
//
// try {
// @SuppressWarnings("resource")
// BufferedReader br = new BufferedReader(new FileReader(file));
// String line = br.readLine();
//
// // firstline is the label
// label = line;
//
// while ((line = br.readLine()) != null) {
// String[] split = line.split("#");
// entries.add(new Entry(Float.parseFloat(split[0]),
// Integer.parseInt(split[1])));
// }
// } catch (IOException e) {
// Log.e(LOG, e.toString());
// }
//
// DataSet ds = new DataSet(entries, label);
// return ds;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) BarEntry(com.github.mikephil.charting.data.BarEntry) Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 49 with Entry

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

the class Approximator method reduceWithDouglasPeuker.

/**
     * uses the douglas peuker algorithm to reduce the given arraylist of
     * entries
     * 
     * @param entries
     * @param epsilon
     * @return
     */
private ArrayList<Entry> reduceWithDouglasPeuker(ArrayList<Entry> entries, double epsilon) {
    // if a shape has 2 or less points it cannot be reduced
    if (epsilon <= 0 || entries.size() < 3) {
        return entries;
    }
    // first and last always stay
    keep[0] = true;
    keep[entries.size() - 1] = true;
    // first and last entry are entry point to recursion
    algorithmDouglasPeucker(entries, epsilon, 0, entries.size() - 1);
    // create a new array with series, only take the kept ones
    ArrayList<Entry> reducedEntries = new ArrayList<Entry>();
    for (int i = 0; i < entries.size(); i++) {
        if (keep[i]) {
            Entry curEntry = entries.get(i);
            reducedEntries.add(new Entry(curEntry.getVal(), curEntry.getXIndex()));
        }
    }
    return reducedEntries;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ArrayList(java.util.ArrayList)

Example 50 with Entry

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

the class Transformer 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) {
        Entry e = entries.get(j / 2);
        // calculate the x-position, depending on datasetcount
        float x = e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet + 0.5f + space * (j / 2) + space / 2f;
        float y = e.getVal();
        valuePoints[j] = x;
        valuePoints[j + 1] = y * phaseY;
    }
    pointValuesToPixel(valuePoints);
    return valuePoints;
}
Also used : Entry(com.github.mikephil.charting.data.Entry)

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