MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

CombinedChart - Reduce y-axis of individual data sets

Open rgray00 opened this issue 11 years ago • 4 comments

Using a combined chart to display candles and bar charts pictured below.

My question is how can I reduce the scale of the y-axis on the BarChart data so that the overlap isn't as large as it currently is.

Thanks for the help!

screen shot 2015-08-20 at 10 33 05 am

rgray00 avatar Aug 20 '15 14:08 rgray00

Finally figured a way to do this.

Using Combined Chart set bar data to an AxisDependency, Left in this case;

        BarDataSet volumeSet = new BarDataSet(yVolumeVals, "Volume Data");
        volumeSet.setDrawValues(false);
        volumeSet.setAxisDependency(YAxis.AxisDependency.LEFT);

Then after getting all the data, calculate largest Y value and set the left axis max value to N times that for desired height. In this case 3x.

        CombinedData combinedData = new CombinedData(xVals);
        combinedData.setData(priceData);
        combinedData.setData(volumeData);
        candleChart.getAxisLeft().setAxisMaxValue(volumeData.getYMax() * 3);
        candleChart.setData(combinedData);
        candleChart.invalidate();

Thanks again @PhilJay for the awesome library!

rgray00 avatar Nov 04 '15 17:11 rgray00

My question is how can I reduce the scale of the y-axis on the BarChart data so that the overlap isn't as large as it currently is.

Did you mean BarChat and CandleChart overlap?

minggo avatar Mar 31 '16 01:03 minggo

@gray419 @PhilJay Can BarChart and CandleChart depend on different axis? And they have different unit. If can, then could you tell me how to? Thanks.

minggo avatar Apr 08 '16 15:04 minggo

@minggo yes, you can set bardataset and candledataset on another axis

 public static void setBarDataSet(BarDataSet dataSet) {
        dataSet.setColor(android.support.design.R.color.design_fab_shadow_end_color);
        dataSet.setDrawValues(false);
        dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
        dataSet.setHighlightEnabled(false);
    }
    //----------------------------------------------------------------------------------------------

    public static void setCandleDataSet(CandleDataSet dataSet) {
        dataSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
        dataSet.setShadowColorSameAsCandle(true);
        dataSet.setBarSpace(0.1f);
        dataSet.setDrawValues(false);

        dataSet.setIncreasingColor(Color.GREEN);
        dataSet.setIncreasingPaintStyle(Paint.Style.FILL);

        dataSet.setDecreasingColor(Color.RED);
        dataSet.setDecreasingPaintStyle(Paint.Style.FILL);

        dataSet.setNeutralColor(Color.BLACK);
    }

ghost avatar May 10 '17 13:05 ghost