Java Code Examples for com.github.mikephil.charting.components.YAxis#setGranularityEnabled()

The following examples show how to use com.github.mikephil.charting.components.YAxis#setGranularityEnabled() . 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: BarGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BarGraph(Context context, BarChart chart, String name) {
    mChart = chart;
    mChartName = name;
    mChart.setHorizontalScrollBarEnabled(true);
    mChart.setVerticalScrollBarEnabled(true);
    mChart.setDrawBorders(true);
    mChart.setNoDataText(context.getString(R.string.no_chart_data_available));

    mContext = context;
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    l.setEnabled(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(ColorTemplate.getHoloBlue());
    xAxis.setDrawAxisLine(false);
    xAxis.setGranularityEnabled(true);
    xAxis.setGranularity(1f);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setAxisMinimum(0f);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setGranularityEnabled(true);
    leftAxis.setGranularity((float) 1);

    mChart.setFitBars(true);
    leftAxis.setAxisMinimum(0f);

    mChart.getAxisRight().setEnabled(false);
}
 
Example 2
Source File: TrafficFragment.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void chartYAxisStyling(YAxis yAxis) {
    yAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    yAxis.setTextColor(SettingsActivity.ThemePreferenceFragment.isLight(getContext()) ?
            getResources().getColor(R.color.traffic_chart_text_color_light) :
            getResources().getColor(R.color.traffic_chart_text_color_dark));
    yAxis.setDrawGridLines(false);
    yAxis.setGranularityEnabled(true);
    yAxis.setDrawAxisLine(true);
}
 
Example 3
Source File: BarChartActivitySinus.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_barchart_sinus);

    setTitle("BarChartActivitySinus");

    data = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");

    tvX = findViewById(R.id.tvValueCount);

    seekBarX = findViewById(R.id.seekbarValues);

    chart = findViewById(R.id.chart1);

    chart.setDrawBarShadow(false);
    chart.setDrawValueAboveBar(true);

    chart.getDescription().setEnabled(false);

    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    chart.setMaxVisibleValueCount(60);

    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);

    // draw shadows for each bar that show the maximum value
    // chart.setDrawBarShadow(true);

    // chart.setDrawXLabels(false);

    chart.setDrawGridBackground(false);
    // chart.setDrawYLabels(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tfLight);
    leftAxis.setLabelCount(6, false);
    leftAxis.setAxisMinimum(-2.5f);
    leftAxis.setAxisMaximum(2.5f);
    leftAxis.setGranularityEnabled(true);
    leftAxis.setGranularity(0.1f);

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setTypeface(tfLight);
    rightAxis.setLabelCount(6, false);
    rightAxis.setAxisMinimum(-2.5f);
    rightAxis.setAxisMaximum(2.5f);
    rightAxis.setGranularity(0.1f);

    seekBarX.setOnSeekBarChangeListener(this);
    seekBarX.setProgress(150); // set data

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setForm(LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);

    chart.animateXY(1500, 1500);
}
 
Example 4
Source File: LineChartTime.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_linechart_time);

    setTitle("LineChartTime");

    tvX = findViewById(R.id.tvXMax);
    seekBarX = findViewById(R.id.seekBar1);
    seekBarX.setOnSeekBarChangeListener(this);

    chart = findViewById(R.id.chart1);

    // no description text
    chart.getDescription().setEnabled(false);

    // enable touch gestures
    chart.setTouchEnabled(true);

    chart.setDragDecelerationFrictionCoef(0.9f);

    // enable scaling and dragging
    chart.setDragEnabled(true);
    chart.setScaleEnabled(true);
    chart.setDrawGridBackground(false);
    chart.setHighlightPerDragEnabled(true);

    // set an alternative background color
    chart.setBackgroundColor(Color.WHITE);
    chart.setViewPortOffsets(0f, 0f, 0f, 0f);

    // add data
    seekBarX.setProgress(100);

    // get the legend (only possible after setting data)
    Legend l = chart.getLegend();
    l.setEnabled(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
    xAxis.setTypeface(tfLight);
    xAxis.setTextSize(10f);
    xAxis.setTextColor(Color.WHITE);
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(true);
    xAxis.setTextColor(Color.rgb(255, 192, 56));
    xAxis.setCenterAxisLabels(true);
    xAxis.setGranularity(1f); // one hour
    xAxis.setValueFormatter(new ValueFormatter() {

        private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);

        @Override
        public String getFormattedValue(float value) {

            long millis = TimeUnit.HOURS.toMillis((long) value);
            return mFormat.format(new Date(millis));
        }
    });

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    leftAxis.setTypeface(tfLight);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setDrawGridLines(true);
    leftAxis.setGranularityEnabled(true);
    leftAxis.setAxisMinimum(0f);
    leftAxis.setAxisMaximum(170f);
    leftAxis.setYOffset(-9f);
    leftAxis.setTextColor(Color.rgb(255, 192, 56));

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);
}
 
Example 5
Source File: LineChartActivity2.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart);

        setTitle("LineChartActivity2");

        tvX = findViewById(R.id.tvXMax);
        tvY = findViewById(R.id.tvYMax);

        seekBarX = findViewById(R.id.seekBar1);
        seekBarX.setOnSeekBarChangeListener(this);

        seekBarY = findViewById(R.id.seekBar2);
        seekBarY.setOnSeekBarChangeListener(this);

        chart = findViewById(R.id.chart1);
        chart.setOnChartValueSelectedListener(this);

        // no description text
        chart.getDescription().setEnabled(false);

        // enable touch gestures
        chart.setTouchEnabled(true);

        chart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        chart.setDragEnabled(true);
        chart.setScaleEnabled(true);
        chart.setDrawGridBackground(false);
        chart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        chart.setPinchZoom(true);

        // set an alternative background color
        chart.setBackgroundColor(Color.LTGRAY);

        // add data
        seekBarX.setProgress(20);
        seekBarY.setProgress(30);

        chart.animateX(1500);

        // get the legend (only possible after setting data)
        Legend l = chart.getLegend();

        // modify the legend ...
        l.setForm(LegendForm.LINE);
        l.setTypeface(tfLight);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);
//        l.setYOffset(11f);

        XAxis xAxis = chart.getXAxis();
        xAxis.setTypeface(tfLight);
        xAxis.setTextSize(11f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);

        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.setTypeface(tfLight);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaximum(200f);
        leftAxis.setAxisMinimum(0f);
        leftAxis.setDrawGridLines(true);
        leftAxis.setGranularityEnabled(true);

        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setTypeface(tfLight);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaximum(900);
        rightAxis.setAxisMinimum(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
        rightAxis.setGranularityEnabled(false);
    }
 
Example 6
Source File: DateGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DateGraph(Context context, LineChart chart, String name) {
    mChart = chart;
    mChartName = name;
    mChart.setDoubleTapToZoomEnabled(true);
    mChart.setHorizontalScrollBarEnabled(true);
    mChart.setVerticalScrollBarEnabled(true);
    mChart.setAutoScaleMinMaxEnabled(true);
    mChart.setDrawBorders(true);
    mChart.setNoDataText(context.getString(R.string.no_chart_data_available));

    IMarker marker = new DateGraphMarkerView(mChart.getContext(), R.layout.graph_markerview, mChart);
    mChart.setMarker(marker);

    mContext = context;
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    l.setEnabled(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(ColorTemplate.getHoloBlue());
    xAxis.setDrawAxisLine(true);
    xAxis.setDrawGridLines(true);
    xAxis.setCenterAxisLabels(false);
    xAxis.setGranularity(1); // 1 jour
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        private SimpleDateFormat mFormat = new SimpleDateFormat("dd-MMM"); // HH:mm:ss

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            //long millis = TimeUnit.HOURS.toMillis((long) value);
            mFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
            Date tmpDate = new Date((long) DateConverter.nbMilliseconds(value)); // Convert days in milliseconds
            return mFormat.format(tmpDate);
        }
    });

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setDrawGridLines(true);
    leftAxis.setGranularityEnabled(true);
    leftAxis.setGranularity((float) 0.5);
    leftAxis.resetAxisMinimum();

    mChart.getAxisRight().setEnabled(false);
}
 
Example 7
Source File: MiniDateGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public MiniDateGraph(Context context, LineChart chart, String name) {
    mChart = chart;
    mChartName = name;
    mChart.getDescription().setEnabled(false);
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setHorizontalScrollBarEnabled(false);
    mChart.setVerticalScrollBarEnabled(false);
    mChart.setAutoScaleMinMaxEnabled(false);
    mChart.setDrawBorders(false);
    mChart.setViewPortOffsets(6f, 6f, 6f, 6f);
    mChart.animateY(1000, Easing.EaseInOutBack); // animate horizontal 3000 milliseconds
    mChart.setClickable(false);

    mChart.getAxisRight().setDrawLabels(false);
    mChart.getAxisLeft().setDrawLabels(false);
    mChart.getLegend().setEnabled(false);
    mChart.setPinchZoom(false);
    mChart.setDescription(null);
    mChart.setTouchEnabled(false);
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setNoDataText(context.getString(R.string.no_chart_data_available));

    mContext = context;
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    l.setEnabled(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setDrawLabels(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(ColorTemplate.getHoloBlue());
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(false);
    xAxis.setCenterAxisLabels(false);
    xAxis.setGranularity(1); // 1 jour

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setEnabled(false);
    leftAxis.setDrawZeroLine(false);
    leftAxis.setDrawLabels(false);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setDrawGridLines(false);
    leftAxis.setGranularityEnabled(false);

    mChart.getAxisRight().setEnabled(false);
}
 
Example 8
Source File: YAxisChartBase.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
protected void setYAxisConfig(YAxis axis, ReadableMap propMap) {
    if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMaxValue")) {
        axis.setAxisMaxValue((float) propMap.getDouble("axisMaxValue"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMinValue")) {
        axis.setAxisMinValue((float) propMap.getDouble("axisMinValue"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "inverted")) {
        axis.setInverted(propMap.getBoolean("inverted"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceTop")) {
        axis.setSpaceTop((float) propMap.getDouble("spaceTop"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBottom")) {
        axis.setSpaceBottom((float) propMap.getDouble("spaceBottom"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "showOnlyMinMax")) {
        axis.setShowOnlyMinMax(propMap.getBoolean("showOnlyMinMax"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "labelCount")) {
        boolean labelCountForce = false;
        if (BridgeUtils.validate(propMap, ReadableType.Boolean, "labelCountForce")) {
            labelCountForce = propMap.getBoolean("labelCountForce");
        }
        axis.setLabelCount(propMap.getInt("labelCount"), labelCountForce);
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
        axis.setPosition(YAxis.YAxisLabelPosition.valueOf(propMap.getString("position")));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "granularity")) {
        axis.setGranularity((float) propMap.getDouble("granularity"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "granularityEnabled")) {
        axis.setGranularityEnabled(propMap.getBoolean("granularityEnabled"));
    }


    // formatting
    if (BridgeUtils.validate(propMap, ReadableType.String, "valueFormatter")) {
        String valueFormatter = propMap.getString("valueFormatter");

        if ("largeValue".equals(valueFormatter)) {
            axis.setValueFormatter(new LargeValueFormatter());
        } else if ("percent".equals(valueFormatter)) {
            axis.setValueFormatter(new PercentFormatter());
        } else {
            axis.setValueFormatter(new CustomFormatter(valueFormatter));
        }
    }

    // TODO docs says the remaining config needs to be applied before setting data. Test it
    // zero line
    if (BridgeUtils.validate(propMap, ReadableType.Map, "zeroLine")) {
        ReadableMap zeroLineConfig = propMap.getMap("zeroLine");

        if (BridgeUtils.validate(zeroLineConfig, ReadableType.Boolean, "enabled")) {
            axis.setDrawZeroLine(zeroLineConfig.getBoolean("enabled"));
        }
        if (BridgeUtils.validate(zeroLineConfig, ReadableType.Number, "lineWidth")) {
            axis.setZeroLineWidth((float) zeroLineConfig.getDouble("lineWidth"));
        }
        if (BridgeUtils.validate(zeroLineConfig, ReadableType.String, "lineColor")) {
            axis.setZeroLineColor(Color.parseColor(zeroLineConfig.getString("lineColor")));
        }
    }
}