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

The following examples show how to use com.github.mikephil.charting.components.AxisBase. 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: QuotationFragment.java    From bitshares_wallet with MIT License 6 votes vote down vote up
private void updateChartData(List<HistoryPrice> historyPriceList) {
    class xAxisValueFormater implements IAxisValueFormatter {
        private List<HistoryPrice> mListPrices;

        public xAxisValueFormater(List<HistoryPrice> listPrices) {
            mListPrices = listPrices;
        }
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            int nValue = (int)value;
            if (nValue < mListPrices.size()) {
                Date date = mListPrices.get(nValue).date;
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd HH:mm");

                return simpleDateFormat.format(date);
            } else {
                return "";
            }
        }
    }

    initializeData(historyPriceList);
    IAxisValueFormatter xvalueFormater = new xAxisValueFormater(historyPriceList);
    mChart.getXAxis().setValueFormatter(xvalueFormater);
}
 
Example #2
Source File: AxisRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans, AxisBase axis) {
    super(viewPortHandler);

    this.mTrans = trans;
    this.mAxis = axis;

    if (mViewPortHandler != null) {

        mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

        mGridPaint = new Paint();
        mGridPaint.setColor(Color.GRAY);
        mGridPaint.setStrokeWidth(1f);
        mGridPaint.setStyle(Style.STROKE);
        mGridPaint.setAlpha(90);

        mAxisLinePaint = new Paint();
        mAxisLinePaint.setColor(Color.BLACK);
        mAxisLinePaint.setStrokeWidth(1f);
        mAxisLinePaint.setStyle(Style.STROKE);

        mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mLimitLinePaint.setStyle(Paint.Style.STROKE);
    }
}
 
Example #3
Source File: AxisRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans, AxisBase axis) {
    super(viewPortHandler);

    this.mTrans = trans;
    this.mAxis = axis;

    if(mViewPortHandler != null) {

        mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

        mGridPaint = new Paint();
        mGridPaint.setColor(Color.GRAY);
        mGridPaint.setStrokeWidth(1f);
        mGridPaint.setStyle(Style.STROKE);
        mGridPaint.setAlpha(90);

        mAxisLinePaint = new Paint();
        mAxisLinePaint.setColor(Color.BLACK);
        mAxisLinePaint.setStrokeWidth(1f);
        mAxisLinePaint.setStyle(Style.STROKE);

        mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mLimitLinePaint.setStyle(Paint.Style.STROKE);
    }
}
 
Example #4
Source File: XAxisValueFormatter.java    From your-local-weather with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getAxisLabel(float value, AxisBase axis) {
    int valuesIndex = (int) value;
    Long dataTime = hourIndexes.get(valuesIndex);
    if (dataTime == null) {
        return "";
    }
    calendar.setTimeInMillis(dataTime * 1000);
    int currentHourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
    if (((lastDayUsed == null) || (lastDayUsed != calendar.get(Calendar.DAY_OF_YEAR))) &&
            (currentHourOfDay >= 10) && (currentHourOfDay <= 14)) {
        lastDayUsed = calendar.get(Calendar.DAY_OF_YEAR);
        return format.format(calendar.getTime());
    } else {
        return "";
    }
}
 
Example #5
Source File: PFAXAxisLabels.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis)
{
    if ( value == 0.0 || labels.isEmpty() )
    {
        return StringUtils.EMPTY;
    }
    else
    {
        value = value - 1;
        if ( value >= labels.size() )
        {
            return StringUtils.EMPTY;
        }
        else
        {
            return labels.get((int) value);
        }
    }
}
 
Example #6
Source File: AxisRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans, AxisBase axis) {
    super(viewPortHandler);

    this.mTrans = trans;
    this.mAxis = axis;

    if(mViewPortHandler != null) {

        mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

        mGridPaint = new Paint();
        mGridPaint.setColor(Color.GRAY);
        mGridPaint.setStrokeWidth(1f);
        mGridPaint.setStyle(Style.STROKE);
        mGridPaint.setAlpha(90);

        mAxisLinePaint = new Paint();
        mAxisLinePaint.setColor(Color.BLACK);
        mAxisLinePaint.setStrokeWidth(1f);
        mAxisLinePaint.setStyle(Style.STROKE);

        mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mLimitLinePaint.setStyle(Paint.Style.STROKE);
    }
}
 
Example #7
Source File: TrafficFragment.java    From gito-github-client with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void chartXAxisStyling(XAxis xAxis) {
    xAxis.setPosition(XAxis.XAxisPosition.TOP);
    xAxis.setTextColor(getResources().getColor(R.color.traffic_chart_text_color_light));
    xAxis.setDrawAxisLine(true);
    xAxis.setDrawGridLines(false);
    xAxis.setCenterAxisLabels(true);
    xAxis.setValueFormatter(new AxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return Utils.humanReadable((long) value);
        }

        @Override
        public int getDecimalDigits() {
            return 0;
        }
    });
}
 
Example #8
Source File: KLineChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 副图指标BOLL
 */
public void setBOLLToChart() {
    if (barChart != null) {
        if (barChart.getBarData() != null) {
            barChart.getBarData().clearValues();
        }
        if (barChart.getLineData() != null) {
            barChart.getLineData().clearValues();
        }
        if (barChart.getCandleData() != null) {
            barChart.getCandleData().clearValues();
        }

        axisLeftBar.resetAxisMaximum();
        axisLeftBar.resetAxisMinimum();
        axisLeftBar.setValueFormatter(new ValueFormatter() {
            @Override
            public String getAxisLabel(float value, AxisBase axis) {
                return NumberUtils.keepPrecision(value, precision);
            }
        });

        CombinedData combinedData = barChart.getData();
        combinedData.setData(new CandleData(kLineData.getBollCandleDataSet()));
        combinedData.setData(new LineData(kLineData.getLineDataBOLL()));
        barChart.notifyDataSetChanged();
        barChart.invalidate();
    }
}
 
Example #9
Source File: TickChart.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (mList != null && value < mList.size()) {
        return DateUtils.formatTime(mList.get((int) value).getDate());
    }
    return "";
}
 
Example #10
Source File: IndexAxisValueFormatter.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public String getFormattedValue(float value, AxisBase axis) {
    int index = Math.round(value);

    if (index < 0 || index >= mValueCount || index != (int)value)
        return "";

    return mValues[index];
}
 
Example #11
Source File: IndexAxisValueFormatter.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public String getFormattedValue(float value, AxisBase axis) {
    int index = Math.round(value);

    if (index < 0 || index >= mValueCount || index != (int)value)
        return "";

    return mValues[index];
}
 
Example #12
Source File: HoursMinutesXAxisValueFormatter.java    From AndroidApp with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (value >= labels.size()) {
        return "";
    }
    DateFormat df = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(Long.parseLong(labels.get((int) value)));
    return (df.format(cal.getTime()));
}
 
Example #13
Source File: YAxisValueFormatter.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getAxisLabel(float value, AxisBase axis) {
    if (axis.mEntries[axis.mEntries.length -1] == value) {
        return unit;
    }
    return decimalFormat.format(value);
}
 
Example #14
Source File: MyValueFormatter.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public String getAxisLabel(float value, AxisBase axis) {
    if (axis instanceof XAxis) {
        return mFormat.format(value);
    } else if (value > 0) {
        return mFormat.format(value) + suffix;
    } else {
        return mFormat.format(value);
    }
}
 
Example #15
Source File: KLineChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 副图指标RSI
 */
public void setRSIToChart() {
    if (barChart != null) {
        if (barChart.getBarData() != null) {
            barChart.getBarData().clearValues();
        }
        if (barChart.getLineData() != null) {
            barChart.getLineData().clearValues();
        }
        if (barChart.getCandleData() != null) {
            barChart.getCandleData().clearValues();
        }

        axisLeftBar.resetAxisMaximum();
        axisLeftBar.resetAxisMinimum();
        axisLeftBar.setValueFormatter(new ValueFormatter() {
            @Override
            public String getAxisLabel(float value, AxisBase axis) {
                return NumberUtils.keepPrecision(value, precision);
            }
        });

        CombinedData combinedData = barChart.getData();
        combinedData.setData(new LineData(kLineData.getLineDataRSI()));
        barChart.notifyDataSetChanged();
        barChart.invalidate();
    }
}
 
Example #16
Source File: KLineChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 副图指标MACD
 */
public void setMACDToChart() {
    if (barChart != null) {
        if (barChart.getBarData() != null) {
            barChart.getBarData().clearValues();
        }
        if (barChart.getLineData() != null) {
            barChart.getLineData().clearValues();
        }
        if (barChart.getCandleData() != null) {
            barChart.getCandleData().clearValues();
        }

        axisLeftBar.resetAxisMaximum();
        axisLeftBar.resetAxisMinimum();
        axisLeftBar.setValueFormatter(new ValueFormatter() {
            @Override
            public String getAxisLabel(float value, AxisBase axis) {
                return NumberUtils.keepPrecision(value, precision);
            }
        });

        CombinedData combinedData = barChart.getData();
        combinedData.setData(new LineData(kLineData.getLineDataMACD()));
        combinedData.setData(new BarData(kLineData.getBarDataMACD()));
        barChart.notifyDataSetChanged();
        barChart.invalidate();
    }
}
 
Example #17
Source File: KLineChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 副图指标KDJ
 */
public void setKDJToChart() {
    if (barChart != null) {
        if (barChart.getBarData() != null) {
            barChart.getBarData().clearValues();
        }
        if (barChart.getLineData() != null) {
            barChart.getLineData().clearValues();
        }
        if (barChart.getCandleData() != null) {
            barChart.getCandleData().clearValues();
        }

        axisLeftBar.resetAxisMaximum();
        axisLeftBar.resetAxisMinimum();
        axisLeftBar.setValueFormatter(new ValueFormatter() {
            @Override
            public String getAxisLabel(float value, AxisBase axis) {
                return NumberUtils.keepPrecision(value, precision);
            }
        });

        CombinedData combinedData = barChart.getData();
        combinedData.setData(new LineData(kLineData.getLineDataKDJ()));
        barChart.notifyDataSetChanged();
        barChart.invalidate();
    }
}
 
Example #18
Source File: DontShowNegativeFormatter.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (dispalyInUsd) {
        return value >= 0 ? ((int) value) + "" : "";
    } else {
        return value >= 0 ? Math.floor(value * 1000) / 1000 + "" : "";
    }
}
 
Example #19
Source File: StatActivity.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
private void drawHourChart(int[][] data){
//        List<BarEntry> popupEntries = new ArrayList<>();
        List<BarEntry> lookupEntries = new ArrayList<>();
        List<BarEntry> cardaddEntries = new ArrayList<>();
        for(int i = 0; i < 24; i ++){
//            popupEntries.add(new BarEntry(i, data[0][i]));
            lookupEntries.add(new BarEntry(i, new float[] {data[1][i], data[2][i]}));
        }
        BarDataSet barDataSet = new BarDataSet(lookupEntries, "Bar");
        barDataSet.setStackLabels(new String[]{"Lookups", "Cards"});
        barDataSet.setDrawValues(false);
        barDataSet.setColors(DARK_PINK, DARK_GREEN);
        BarData barData = new BarData(barDataSet);
        mHourChart.setData(barData);
        mHourChart.getDescription().setText("hour");
        //mHourChart.getDescription().setTextAlign();
        mHourChart.getXAxis().setDrawGridLines(false);
        mHourChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        mHourChart.getAxisRight().setEnabled(false);
        //mHourChart.getAxisLeft().setDrawGridLines(false);
        mHourChart.getXAxis().setValueFormatter(
                new IAxisValueFormatter() {
                    @Override
                    public String getFormattedValue(float value, AxisBase axis) {
                        return ((int) value) + "";
                    }
                }
        );
        mHourChart.getXAxis().setLabelCount(24);
        mHourChart.getXAxis().setAxisMinimum(-0.5f);
        mHourChart.getXAxis().setAxisMaximum(23.5f);
        mHourChart.getLegend().setEnabled(false);
        mHourChart.invalidate();
    }
 
Example #20
Source File: ReportAdapter.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (this.values.size() <= (int) value || (int) value < 0) {
        return "--";
    }
    return this.values.get((int) value);
}
 
Example #21
Source File: MainActivity.java    From WheelLogAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (value < xAxis_labels.size())
        return xAxis_labels.get((int) value);
    else
        return "";
}
 
Example #22
Source File: GraphActivity.java    From Simple-Accounting with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
	if(value % 1 == 0) {//check if has decimal part
		return String.valueOf((int) value);
	} else {
		return "";
	}
}
 
Example #23
Source File: HourAxisValueFormatter.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called when a value from an axis is to be formatted before being drawn.
 *
 * @param value the value to be formatted.
 * @param axis  the axis the value belongs to.
 * @return timestamp formatted.
 */
@Override
public String getFormattedValue(float value, AxisBase axis) {
    // relativeTimestamp = originalTimestamp - referenceTimestamp
    long relativeTimestamp = (long) value;
    // Retrieve absolute timestamp (referenceTimestamp + relativeTimestamp)
    long originalTimestamp = referenceTimestamp + relativeTimestamp;
    // Convert timestamp to hour:minute
    return getHour(originalTimestamp);
}
 
Example #24
Source File: PFAYAxisLabels.java    From privacy-friendly-shopping-list with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis)
{
    String numberSuffix = StringUtils.EMPTY;
    if ( numberScale != null && value > numberScale.getValue(context) )
    {
        value /= numberScale.getValue(context);
        numberSuffix = numberScale.getAbbreviation(context) + StringUtils.SPACE;
    }
    return format.format(value) + SPACE + numberSuffix + unit;
}
 
Example #25
Source File: ReportAdapter.java    From privacy-friendly-interval-timer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (this.values.size() <= (int) value || (int) value < 0) {
        return "--";
    }
    return this.values.get((int) value);
}
 
Example #26
Source File: AnalysisFragment.java    From outlay with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (expenses != null && value < expenses.size()) {
        Expense expense = expenses.get((int) value);
        return DateUtils.toShortString(expense.getReportedWhen());
    } else {
        return null;
    }
}
 
Example #27
Source File: LabelAxisFormatter.java    From AndroidApp with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if ((int)value >= labels.size()) {
        return "";
    }
    return labels.get((int) value);
}
 
Example #28
Source File: DontShowNegativeFormatter.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (dispalyInUsd) {
        return value >= 0 ? ((int) value) + "" : "";
    } else {
        return value >= 0 ? Math.floor(value * 1000) / 1000 + "" : "";
    }
}
 
Example #29
Source File: RainValueFormatter.java    From go-bees with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    return formatRain(value);
}
 
Example #30
Source File: TempValueFormatter.java    From go-bees with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getFormattedValue(float value, AxisBase axis) {
    return formatTemperature(convertValue(value));
}