com.github.mikephil.charting.components.Description Java Examples

The following examples show how to use com.github.mikephil.charting.components.Description. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccelerometerFragment.java    From walt with Apache License 2.0 6 votes vote down vote up
private void drawLatencyChart(List<Entry> phoneEntriesShifted, List<Entry> waltEntries) {
    final ScatterDataSet dataSetWalt =
            new ScatterDataSet(waltEntries, "WALT Events");
    dataSetWalt.setColor(Color.BLUE);
    dataSetWalt.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    dataSetWalt.setScatterShapeSize(8f);

    final ScatterDataSet dataSetPhoneShifted =
            new ScatterDataSet(phoneEntriesShifted, "Phone Events Shifted");
    dataSetPhoneShifted.setColor(Color.RED);
    dataSetPhoneShifted.setScatterShapeSize(10f);
    dataSetPhoneShifted.setScatterShape(ScatterChart.ScatterShape.X);

    final ScatterData scatterData = new ScatterData(dataSetWalt, dataSetPhoneShifted);
    final Description desc = new Description();
    desc.setText("");
    desc.setTextSize(12f);
    latencyChart.setDescription(desc);
    latencyChart.setData(scatterData);
    latencyChart.invalidate();
    latencyChartLayout.setVisibility(View.VISIBLE);
}
 
Example #2
Source File: MainActivity.java    From android-ponewheel with MIT License 5 votes vote down vote up
private void initBatteryChart() {
    mBatteryChart = findViewById(R.id.batteryPieChart);
    // configure pie chart
    mBatteryChart.setUsePercentValues(true);
    mBatteryChart.setDescription(new Description());
    // enable hole and configure
    mBatteryChart.setDrawHoleEnabled(true);
    Legend legend = mBatteryChart.getLegend();
    legend.setEnabled(false);
}
 
Example #3
Source File: DragLatencyFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
private void drawLatencyGraph(double[] ft, double[] fy, double[] lt, double averageBestShift) {
    final ArrayList<Entry> touchEntries = new ArrayList<>();
    final ArrayList<Entry> laserEntries = new ArrayList<>();
    final double[] laserT = new double[lt.length];
    for (int i = 0; i < ft.length; i++) {
        touchEntries.add(new Entry((float) ft[i], (float) fy[i]));
    }
    for (int i = 0; i < lt.length; i++) {
        laserT[i] = lt[i] + averageBestShift;
    }
    final double[] laserY = Utils.interp(laserT, ft, fy);
    for (int i = 0; i < laserY.length; i++) {
        laserEntries.add(new Entry((float) laserT[i], (float) laserY[i]));
    }

    final ScatterDataSet dataSetTouch = new ScatterDataSet(touchEntries, "Touch Events");
    dataSetTouch.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    dataSetTouch.setScatterShapeSize(8f);

    final ScatterDataSet dataSetLaser = new ScatterDataSet(laserEntries,
            String.format(Locale.US, "Laser Events  Latency=%.1f ms", averageBestShift));
    dataSetLaser.setColor(Color.RED);
    dataSetLaser.setScatterShapeSize(10f);
    dataSetLaser.setScatterShape(ScatterChart.ScatterShape.X);

    final ScatterData scatterData = new ScatterData(dataSetTouch, dataSetLaser);
    final Description desc = new Description();
    desc.setText("Y-Position [pixels] vs. Time [ms]");
    desc.setTextSize(12f);
    latencyChart.setDescription(desc);
    latencyChart.setData(scatterData);
    latencyChartLayout.setVisibility(View.VISIBLE);
}
 
Example #4
Source File: ScreenResponseFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
private void drawBrightnessChart() {
    final String brightnessCurveString = brightnessCurveData.toString();
    List<Entry> entries = new ArrayList<>();

    // "u" marks the start of the brightness curve data
    int startIndex = brightnessCurveString.indexOf("u") + 1;
    int endIndex = brightnessCurveString.indexOf("end");
    if (endIndex == -1) endIndex = brightnessCurveString.length();

    String[] brightnessStrings =
            brightnessCurveString.substring(startIndex, endIndex).trim().split("\n");
    for (String str : brightnessStrings) {
        String[] arr = str.split(" ");
        final float timestampMs = Integer.parseInt(arr[0]) / 1000f;
        final float brightness = Integer.parseInt(arr[1]);
        entries.add(new Entry(timestampMs, brightness));
    }
    LineDataSet dataSet = new LineDataSet(entries, "Brightness");
    dataSet.setColor(Color.BLACK);
    dataSet.setValueTextColor(Color.BLACK);
    dataSet.setCircleColor(Color.BLACK);
    dataSet.setCircleRadius(1.5f);
    dataSet.setCircleColorHole(Color.DKGRAY);
    LineData lineData = new LineData(dataSet);
    brightnessChart.setData(lineData);
    final Description desc = new Description();
    desc.setText("Screen Brightness [digital level 0-1023] vs. Time [ms]");
    desc.setTextSize(12f);
    brightnessChart.setDescription(desc);
    brightnessChart.getLegend().setEnabled(false);
    brightnessChart.invalidate();
    brightnessChartLayout.setVisibility(View.VISIBLE);
}
 
Example #5
Source File: AudioFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
private void drawWaveformChart() {
    final short[] wave = AudioTest.getRecordedWave();
    List<Entry> entries = new ArrayList<>();
    int frameRate = audioTest.getOptimalFrameRate();
    for (int i = 0; i < wave.length; i++) {
        float timeStamp = (float) i / frameRate * 1000f;
        entries.add(new Entry(timeStamp, (float) wave[i]));
    }
    LineDataSet dataSet = new LineDataSet(entries, "Waveform");
    dataSet.setColor(Color.BLACK);
    dataSet.setValueTextColor(Color.BLACK);
    dataSet.setCircleColor(ContextCompat.getColor(getContext(), R.color.DarkGreen));
    dataSet.setCircleRadius(1.5f);
    dataSet.setCircleColorHole(Color.DKGRAY);
    LineData lineData = new LineData(dataSet);
    chart.setData(lineData);

    LimitLine line = new LimitLine(audioTest.getThreshold(), "Threshold");
    line.setLineColor(Color.RED);
    line.setLabelPosition(LimitLine.LimitLabelPosition.LEFT_TOP);
    line.setLineWidth(2f);
    line.setTextColor(Color.DKGRAY);
    line.setTextSize(10f);
    chart.getAxisLeft().addLimitLine(line);

    final Description desc = new Description();
    desc.setText("Wave [digital level -32768 to +32767] vs. Time [ms]");
    desc.setTextSize(12f);
    chart.setDescription(desc);
    chart.getLegend().setEnabled(false);
    chart.invalidate();
    chartLayout.setVisibility(View.VISIBLE);
}
 
Example #6
Source File: BaseView.java    From android-kline with Apache License 2.0 4 votes vote down vote up
protected void setDescription(Chart chart, String text) {
        Description description = chart.getDescription();
//        float dx = chart.getWidth() - chart.getViewPortHandler().offsetRight() - description.getXOffset();
//        description.setPosition(dx, description.getTextSize());
        description.setText(text);
    }
 
Example #7
Source File: StatsActivity.java    From android with MIT License 4 votes vote down vote up
private void createPieChart(List<Long> contacts, List<Long> voicemails, List<Long> unavailables, long firstTimestamp) {
    Date date = new Date(firstTimestamp);

    ArrayList<Integer> colorsList = new ArrayList<>();
    // Create pie pieChart data entries and add correct colors.
    ArrayList<PieEntry> entries = new ArrayList<>();
    if (contacts.size() > 0) {
        entries.add(new PieEntry(contacts.size(), getResources().getString(R.string.contact_n)));
        colorsList.add(getResources().getColor(R.color.contacted_color));
    }
    if (voicemails.size() > 0) {
        entries.add(new PieEntry(voicemails.size(),  getResources().getString(R.string.voicemail_n)));
        colorsList.add(getResources().getColor(R.color.voicemail_color));
    }
    if (unavailables.size() > 0) {
        entries.add(new PieEntry(unavailables.size(),  getResources().getString(R.string.unavailable_n)));
        colorsList.add(getResources().getColor(R.color.unavailable_color));
    }

    PieDataSet dataSet = new PieDataSet(entries, getResources().getString(R.string.menu_stats));

    // Add colors and set visual properties for pie pieChart.
    dataSet.setColors(colorsList);
    dataSet.setSliceSpace(3f);
    dataSet.setSelectionShift(5f);
    dataSet.setValueLinePart1OffsetPercentage(80.f);
    dataSet.setValueLinePart1Length(.1f);
    dataSet.setValueLinePart2Length(.5f);
    dataSet.setValueLineColor(getResources().getColor(R.color.colorPrimaryDark));
    dataSet.setYValuePosition(PieDataSet.ValuePosition.INSIDE_SLICE);
    dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);

    PieData data = new PieData(dataSet);
    data.setValueTextSize(18f);
    data.setValueFormatter(new DefaultValueFormatter(0));
    data.setValueTextColor(Color.WHITE);

    SpannableString insideCircleText = new SpannableString(getResources().getString(R.string.stats_summary_total)
            +"\n"
            + Integer.toString(voicemails.size()+contacts.size()+unavailables.size())
            + "\n"
            + this.dateFormat.format(date)
            + "-"
            + this.dateFormat.format(new Date(System.currentTimeMillis()))
    );
    insideCircleText.setSpan(new RelativeSizeSpan(2f), 0, insideCircleText.length() - 17, 0);

    pieChart.setData(data);
    pieChart.setCenterText(insideCircleText);
    pieChart.setCenterTextColor(getResources().getColor(R.color.colorPrimaryDark));
    pieChart.setCenterTextSize(11f);
    pieChart.setHoleRadius(70);
    pieChart.setEntryLabelColor(getResources().getColor(R.color.colorPrimaryDark));
    pieChart.getLegend().setEnabled(false);
    pieChart.setDescription(new Description());
    pieChart.getDescription().setText("");
    pieChart.invalidate();
}
 
Example #8
Source File: HistogramChart.java    From walt with Apache License 2.0 4 votes vote down vote up
public HistogramChart(Context context, AttributeSet attrs) {
    super(context, attrs);
    inflate(getContext(), R.layout.histogram, this);

    barChart = (BarChart) findViewById(R.id.bar_chart);
    findViewById(R.id.button_close_bar_chart).setOnClickListener(this);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HistogramChart);
    final String descString;
    final int numDataSets;
    final float binWidth;
    try {
        descString = a.getString(R.styleable.HistogramChart_description);
        numDataSets = a.getInteger(R.styleable.HistogramChart_numDataSets, 1);
        binWidth = a.getFloat(R.styleable.HistogramChart_binWidth, 5f);
    } finally {
        a.recycle();
    }

    ArrayList<IBarDataSet> dataSets = new ArrayList<>(numDataSets);
    for (int i = 0; i < numDataSets; i++) {
        final BarDataSet dataSet = new BarDataSet(new ArrayList<BarEntry>(), "");
        dataSet.setColor(ColorTemplate.MATERIAL_COLORS[i]);
        dataSets.add(dataSet);
    }

    BarData barData = new BarData(dataSets);
    barData.setBarWidth((1f - GROUP_SPACE)/numDataSets);
    barChart.setData(barData);
    histogramData = new HistogramData(numDataSets, binWidth);
    groupBars(barData);
    final Description desc = new Description();
    desc.setText(descString);
    desc.setTextSize(12f);
    barChart.setDescription(desc);

    XAxis xAxis = barChart.getXAxis();
    xAxis.setGranularityEnabled(true);
    xAxis.setGranularity(1);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setValueFormatter(new IAxisValueFormatter() {
        DecimalFormat df = new DecimalFormat("#.##");

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return df.format(histogramData.getDisplayValue(value));
        }
    });

    barChart.setFitBars(true);
    barChart.invalidate();
}
 
Example #9
Source File: Chart.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
/**
 * Sets a new Description object for the chart.
 *
 * @param desc
 */
public void setDescription(Description desc) {
    this.mDescription = desc;
}
 
Example #10
Source File: Chart.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
/**
 * Returns the Description object of the chart that is responsible for holding all information related
 * to the description text that is displayed in the bottom right corner of the chart (by default).
 *
 * @return
 */
public Description getDescription() {
    return mDescription;
}
 
Example #11
Source File: Chart.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Sets a new Description object for the chart.
 *
 * @param desc
 */
public void setDescription(Description desc) {
    this.mDescription = desc;
}
 
Example #12
Source File: Chart.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Returns the Description object of the chart that is responsible for holding all information related
 * to the description text that is displayed in the bottom right corner of the chart (by default).
 *
 * @return
 */
public Description getDescription() {
    return mDescription;
}
 
Example #13
Source File: Chart.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Sets a new Description object for the chart.
 *
 * @param desc
 */
public void setDescription(Description desc) {
    this.mDescription = desc;
}
 
Example #14
Source File: Chart.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the Description object of the chart that is responsible for holding all information related
 * to the description text that is displayed in the bottom right corner of the chart (by default).
 *
 * @return
 */
public Description getDescription() {
    return mDescription;
}