Java Code Examples for com.github.mikephil.charting.components.XAxis#setAxisMinimum()

The following examples show how to use com.github.mikephil.charting.components.XAxis#setAxisMinimum() . 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: ProcessViewer.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initialize chart for the first time
 * @param totalBytes maximum value for x-axis
 */
private void chartInit(long totalBytes) {
    mLineChart.setBackgroundColor(accentColor);
    mLineChart.getLegend().setEnabled(false);

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

    XAxis xAxis = mLineChart.getXAxis();
    YAxis yAxisLeft = mLineChart.getAxisLeft();
    mLineChart.getAxisRight().setEnabled(false);
    yAxisLeft.setTextColor(Color.WHITE);
    yAxisLeft.setAxisLineColor(Color.TRANSPARENT);
    yAxisLeft.setTypeface(Typeface.DEFAULT_BOLD);
    yAxisLeft.setGridColor(Utils.getColor(getContext(), R.color.white_translucent));

    xAxis.setAxisMaximum(Futils.readableFileSizeFloat(totalBytes));
    xAxis.setAxisMinimum(0.0f);
    xAxis.setAxisLineColor(Color.TRANSPARENT);
    xAxis.setGridColor(Color.TRANSPARENT);
    xAxis.setTextColor(Color.WHITE);
    xAxis.setTypeface(Typeface.DEFAULT_BOLD);
    mLineChart.setData(mLineData);
    mLineChart.invalidate();
}
 
Example 2
Source File: ModelDetailActivity.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void setXAxis(int epochs) {
    final XAxis axis = mChart.getXAxis();
    axis.setEnabled(true);
    axis.setAxisMinimum(1F);
    axis.setAxisMaximum(epochs);
    axis.setPosition(XAxis.XAxisPosition.BOTTOM);
    axis.setDrawAxisLine(true);
    axis.setDrawGridLines(false);
    axis.setGranularity(1F);
    axis.setAvoidFirstLastClipping(true);

    mChart.getAxisRight().setDrawAxisLine(true);
}
 
Example 3
Source File: TestSuiteFragment.java    From SQLite-Performance with The Unlicense 5 votes vote down vote up
private void setupXAxis(BarLineChartBase chart, IAxisValueFormatter formatter) {
    XAxis x = chart.getXAxis();
    x.setGranularity(1.0f);
    x.setDrawGridLines(false);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawAxisLine(false);
    x.setCenterAxisLabels(true);
    x.setAxisMinimum(2.0f);
    x.setAxisMaximum(5.0f);
    x.setValueFormatter(formatter);
}
 
Example 4
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configure styles of weather charts.
 *
 * @param entries   chart data.
 * @param formatter value formatter.
 * @param minVal    min value to show.
 * @param maxVal    max value to show.
 * @return chart formatted.
 */
private LineDataSet configureWeatherChart(
        LineChart chart, int chartName, int colorLineTempChart, int colorFillTempChart,
        List<Entry> entries, IAxisValueFormatter formatter, double minVal, double maxVal) {
    LineDataSet lineDataSet = new LineDataSet(entries, getString(chartName));
    lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    lineDataSet.setDrawValues(false);
    lineDataSet.setValueTextSize(10f);
    lineDataSet.setDrawCircles(false);
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setColor(ContextCompat.getColor(getContext(), colorLineTempChart));
    lineDataSet.setLineWidth(2f);
    lineDataSet.setDrawFilled(true);
    lineDataSet.setFillColor(ContextCompat.getColor(getContext(), colorFillTempChart));
    lineDataSet.setFillAlpha(255);
    // General setup
    chart.setDrawGridBackground(false);
    chart.setDrawBorders(false);
    chart.setViewPortOffsets(0, 0, 0, 0);
    chart.getDescription().setEnabled(false);
    chart.getLegend().setEnabled(false);
    chart.setTouchEnabled(false);
    // X axis setup
    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);
    xAxis.setAxisMinimum(0);
    xAxis.setAxisMaximum(lastTimestamp);
    // Y axis setup
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setEnabled(false);
    leftAxis.setAxisMaximum((float) (maxVal));
    leftAxis.setAxisMinimum((float) (minVal));
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setAxisMaximum((float) (maxVal));
    rightAxis.setAxisMinimum((float) (minVal));
    rightAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    rightAxis.setValueFormatter(formatter);
    return lineDataSet;
}
 
Example 5
Source File: HistogramChart.java    From walt with Apache License 2.0 5 votes vote down vote up
private void recalculateXAxis() {
    final XAxis xAxis = barChart.getXAxis();
    xAxis.setAxisMinimum(0);
    xAxis.setAxisMaximum(histogramData.getNumBins());
    barChart.notifyDataSetChanged();
    barChart.invalidate();
}
 
Example 6
Source File: StackedBarActivityNegative.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_age_distribution);

    setTitle("StackedBarActivityNegative");

    chart = findViewById(R.id.chart1);
    chart.setOnChartValueSelectedListener(this);
    chart.setDrawGridBackground(false);
    chart.getDescription().setEnabled(false);

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

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

    chart.getAxisLeft().setEnabled(false);
    chart.getAxisRight().setAxisMaximum(25f);
    chart.getAxisRight().setAxisMinimum(-25f);
    chart.getAxisRight().setDrawGridLines(false);
    chart.getAxisRight().setDrawZeroLine(true);
    chart.getAxisRight().setLabelCount(7, false);
    chart.getAxisRight().setValueFormatter(new CustomFormatter());
    chart.getAxisRight().setTextSize(9f);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);
    xAxis.setAxisMinimum(0f);
    xAxis.setAxisMaximum(110f);
    xAxis.setCenterAxisLabels(true);
    xAxis.setLabelCount(12);
    xAxis.setGranularity(10f);
    xAxis.setValueFormatter(new ValueFormatter() {

        private final DecimalFormat format = new DecimalFormat("###");

        @Override
        public String getFormattedValue(float value) {
            return format.format(value) + "-" + format.format(value + 10);
        }
    });

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);

    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> values = new ArrayList<>();
    values.add(new BarEntry(5, new float[]{ -10, 10 }));
    values.add(new BarEntry(15, new float[]{ -12, 13 }));
    values.add(new BarEntry(25, new float[]{ -15, 15 }));
    values.add(new BarEntry(35, new float[]{ -17, 17 }));
    values.add(new BarEntry(45, new float[]{ -19, 20 }));
    values.add(new BarEntry(45, new float[]{ -19, 20 }, getResources().getDrawable(R.drawable.star)));
    values.add(new BarEntry(55, new float[]{ -19, 19 }));
    values.add(new BarEntry(65, new float[]{ -16, 16 }));
    values.add(new BarEntry(75, new float[]{ -13, 14 }));
    values.add(new BarEntry(85, new float[]{ -10, 11 }));
    values.add(new BarEntry(95, new float[]{ -5, 6 }));
    values.add(new BarEntry(105, new float[]{ -1, 2 }));

    BarDataSet set = new BarDataSet(values, "Age Distribution");
    set.setDrawIcons(false);
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setColors(Color.rgb(67,67,72), Color.rgb(124,181,236));
    set.setStackLabels(new String[]{
            "Men", "Women"
    });

    BarData data = new BarData(set);
    data.setBarWidth(8.5f);
    chart.setData(data);
    chart.invalidate();
}
 
Example 7
Source File: CombinedChartActivity.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_combined);

    setTitle("CombinedChartActivity");

    chart = findViewById(R.id.chart1);
    chart.getDescription().setEnabled(false);
    chart.setBackgroundColor(Color.WHITE);
    chart.setDrawGridBackground(false);
    chart.setDrawBarShadow(false);
    chart.setHighlightFullBarEnabled(false);

    // draw bars behind lines
    chart.setDrawOrder(new DrawOrder[]{
            DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
    });

    Legend l = chart.getLegend();
    l.setWordWrapEnabled(true);
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setDrawGridLines(false);
    leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setAxisMinimum(0f);
    xAxis.setGranularity(1f);
    xAxis.setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value) {
            return months[(int) value % months.length];
        }
    });

    CombinedData data = new CombinedData();

    data.setData(generateLineData());
    data.setData(generateBarData());
    data.setData(generateBubbleData());
    data.setData(generateScatterData());
    data.setData(generateCandleData());
    data.setValueTypeface(tfLight);

    xAxis.setAxisMaximum(data.getXMax() + 0.25f);

    chart.setData(data);
    chart.invalidate();
}
 
Example 8
Source File: InvertedLineChartActivity.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("InvertedLineChartActivity");

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

    seekBarX = findViewById(R.id.seekBar1);
    seekBarY = findViewById(R.id.seekBar2);

    seekBarY.setOnSeekBarChangeListener(this);
    seekBarX.setOnSeekBarChangeListener(this);

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

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

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

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

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

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

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
    mv.setChartView(chart); // For bounds control
    chart.setMarker(mv); // Set the marker to the chart

    XAxis xl = chart.getXAxis();
    xl.setAvoidFirstLastClipping(true);
    xl.setAxisMinimum(0f);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setInverted(true);
    leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);

    // add data
    seekBarX.setProgress(25);
    seekBarY.setProgress(50);

    // // restrain the maximum scale-out factor
    // chart.setScaleMinima(3f, 3f);
    //
    // // center the view to a specific position inside the chart
    // chart.centerViewPort(10, 50);

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

    // modify the legend ...
    l.setForm(LegendForm.LINE);

    // don't forget to refresh the drawing
    chart.invalidate();
}
 
Example 9
Source File: BaseView.java    From android-kline with Apache License 2.0 4 votes vote down vote up
protected void initBottomChart(AppCombinedChart chart) {
        chart.setScaleEnabled(true);
        chart.setDrawBorders(false);
        chart.setBorderWidth(1);
        chart.setDragEnabled(true);
        chart.setScaleYEnabled(false);
        chart.setAutoScaleMinMaxEnabled(true);
        chart.setDragDecelerationEnabled(false);
        chart.setHighlightPerDragEnabled(false);
        Legend lineChartLegend = chart.getLegend();
        lineChartLegend.setEnabled(false);


        XAxis xAxisVolume = chart.getXAxis();
        xAxisVolume.setDrawLabels(true);
        xAxisVolume.setDrawAxisLine(false);
        xAxisVolume.setDrawGridLines(false);
        xAxisVolume.setTextColor(mAxisColor);
        xAxisVolume.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxisVolume.setLabelCount(3, true);
        xAxisVolume.setAvoidFirstLastClipping(true);
        xAxisVolume.setAxisMinimum(-0.5f);

        xAxisVolume.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                if (mData.isEmpty()) {
                    return "";
                }
                if (value < 0) {
                    value = 0;
                }
                if (value < mData.size()) {
                    return DateUtils.formatDate(mData.get((int) value).getDate(), mDateFormat);
                }
                return "";
            }
        });

        YAxis axisLeftVolume = chart.getAxisLeft();
        axisLeftVolume.setDrawLabels(true);
        axisLeftVolume.setDrawGridLines(false);
        axisLeftVolume.setLabelCount(3, true);
        axisLeftVolume.setDrawAxisLine(false);
        axisLeftVolume.setTextColor(mAxisColor);
        axisLeftVolume.setSpaceTop(10);
        axisLeftVolume.setSpaceBottom(0);
        axisLeftVolume.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
        /*axisLeftVolume.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                String s;
                if (value > 10000) {
                    s = (int) (value / 10000) + "w";
                } else if (value > 1000) {
                    s = (int) (value / 1000) + "k";
                } else {
                    s = (int) value + "";
                }
                return String.format(Locale.getDefault(), "%1$5s", s);
            }
        });
*/
        Transformer leftYTransformer = chart.getRendererLeftYAxis().getTransformer();
        ColorContentYAxisRenderer leftColorContentYAxisRenderer = new ColorContentYAxisRenderer(chart.getViewPortHandler(), chart.getAxisLeft(), leftYTransformer);
        leftColorContentYAxisRenderer.setLabelInContent(true);
        leftColorContentYAxisRenderer.setUseDefaultLabelXOffset(false);
        chart.setRendererLeftYAxis(leftColorContentYAxisRenderer);

        //右边y
        YAxis axisRightVolume = chart.getAxisRight();
        axisRightVolume.setDrawLabels(false);
        axisRightVolume.setDrawGridLines(false);
        axisRightVolume.setDrawAxisLine(false);

    }