Search in sources :

Example 1 with MyMarkerView

use of ru.sash0k.thriftbox.charting.MyMarkerView in project Thrift-box by Sash0k.

the class ChartsFragment method onCreateView.

// ============================================================================
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.charts_fragment, container, false);
    TextView month = (TextView) v.findViewById(R.id.current_month);
    long ts = getArguments().getLong(DB.TIMESTAMP);
    month.setText(SDF_MONTH.format(new Date(ts * 1000)));
    // отображение статистики за текущий месяц
    BarChart barChart = (BarChart) v.findViewById(R.id.bar_chart);
    barChart.setDescription("");
    Paint mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mInfoPaint.setColor(getResources().getColor(R.color.primary));
    mInfoPaint.setTextAlign(Paint.Align.CENTER);
    mInfoPaint.setTextSize(com.github.mikephil.charting.utils.Utils.convertDpToPixel(16f));
    barChart.setPaint(mInfoPaint, Chart.PAINT_INFO);
    barChart.setNoDataText(getString(R.string.charts_no_data));
    barChart.setDrawBarShadow(false);
    barChart.setDrawGridBackground(false);
    barChart.setDrawValueAboveBar(false);
    barChart.setPinchZoom(false);
    barChart.setScaleEnabled(false);
    barChart.setDoubleTapToZoomEnabled(false);
    barChart.getXAxis().disableGridDashedLine();
    barChart.getXAxis().setDrawGridLines(false);
    barChart.getXAxis().setEnabled(false);
    barChart.getAxisLeft().setDrawGridLines(false);
    barChart.getAxisLeft().setEnabled(false);
    barChart.getAxisRight().setDrawGridLines(false);
    barChart.getAxisRight().removeAllLimitLines();
    barChart.getAxisRight().setValueFormatter(new FinanceFormatter());
    barChart.getLegend().setEnabled(false);
    barChart.setData(generateMonthlyData());
    // если данных нет, не показывать ось
    barChart.getAxisRight().setEnabled(!barChart.isEmpty());
    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
    mv.setX(mv.getMeasuredWidth());
    barChart.setMarkerView(mv);
    Utils.log("getYMin = " + barChart.getBarData().getYMin());
    Utils.log("getYMax = " + barChart.getBarData().getYMax());
    barChart.animateY(ANIMATION_TIME);
    return v;
}
Also used : BarChart(com.github.mikephil.charting.charts.BarChart) TextView(android.widget.TextView) Paint(android.graphics.Paint) TextView(android.widget.TextView) MyMarkerView(ru.sash0k.thriftbox.charting.MyMarkerView) View(android.view.View) Date(java.util.Date) MyMarkerView(ru.sash0k.thriftbox.charting.MyMarkerView) FinanceFormatter(ru.sash0k.thriftbox.charting.FinanceFormatter)

Aggregations

Paint (android.graphics.Paint)1 View (android.view.View)1 TextView (android.widget.TextView)1 BarChart (com.github.mikephil.charting.charts.BarChart)1 Date (java.util.Date)1 FinanceFormatter (ru.sash0k.thriftbox.charting.FinanceFormatter)1 MyMarkerView (ru.sash0k.thriftbox.charting.MyMarkerView)1