MPandroidchart Double YAxis with different scales

I want my diagram to have two YAxis with different scales such as an image. How can I change the scale for each axis?

enter image description here

+3


source to share


2 answers


Version 2.0.0 beta was released over the weekend with a help CombinedChart

that allows you to display Line-, Bar-, Scatter- and CandleData strings in one chart. So the feature is finally available .

One note that I discovered during my upgrade, you cannot just add addDataSet () for each one, you need to create separate DataSet types (Bar, Line, Scatter, etc.) and then use SetData ( ) for the appropriate type to start rendering.



Here's an example ...

+4


source


The author of the MPAndroidChart library clearly states here ( MPChart - Scatter Chart and LineChart in the same plot ) that this feature is not yet available. So, I'm also looking for a more convenient approach.

Thus, you can display two different chart types as one while still using this library, only by overlapping them.

I did it on my side as follows:
1. Edit the layout of the xml activity having a FrameLayout container in the form of diagrams.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    .......
    <FrameLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:id="@+id/root_view">
    </FrameLayout>
    .......
</LinearLayout>

      

  1. Now, in the Activity class, create the chart objects and attach them to the previous container:


    // construct the charts, as different objects
    // make sure to have valid Data Sets    
    LineChartItem lineChart = new LineChartItem(lineChartDataset, getApplicationContext());
    BarChartItem barChart = new BarChartItem(barChartDataset, getApplicationContext());

    // get the charts' container
    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.root_view);

    // populate the container with the charts' views
    frameLayout.addView(lineChart.getView(0, null, getApplicationContext()));
    frameLayout.addView(barChart.getView(1, null, getApplicationContext()));


      



PROs / CONs for this practice:
PROs

You have more combo charts with MPAndroidChart.
CONS You need to take care of the alignment of the X and Y labels.
Custom Events: Only the top (in Z order) Chart View will receive user input, so you need to make sure that all other chart views behave the same (either handling OR ignoring the input, such as scaling chart or value selection).

I look forward to a quick release of this large library that has this option. Thanks in advance to Philip Jahoda!

+4


source







All Articles