AnyChart not displayed at all in Android

39 Views Asked by At

I am using Android Studio Electric Eel, when I add this component in the layout xml file of a fragment, all UI components disappear in the "Split" view:

 <!-- Pie chart -->
                    <com.anychart.AnyChartView
                        android:id="@+id/anyChartView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        />

removing it, all UI components show properly. I am suspecting this is causing the Pie chart fails to display when running the app.

Here's the app/build.gradle:

implementation 'com.github.AnyChart:AnyChart-Android:1.1.2'

it looks like I can't use 1.1.5 version as shown in their web site: https://github.com/AnyChart/AnyChart-Android/wiki/Getting-started which seems require Java 17, my IDE is Java 11.

Also, the document in above link regarding the configuration in root build.gradle seems not working for me at all:

allprojects {
        repositories {
                ...
                maven { url 'https://jitpack.io' }
        }
}

instead, I have to put the maven url in settings.gradle:

include ':app'
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://jitpack.io'
        }
    }
}

To draw the Pie chart, I used the following code from one of their web page (keep it minimum):

    private void drawPieChart() {
        AnyChartView anyChartView = getActivity().findViewById(R.id.anyChartView);

        Pie pie = AnyChart.pie();

        List<DataEntry> data = new ArrayList<>();
        data.add(new ValueDataEntry("Apples", 6371664));
        data.add(new ValueDataEntry("Pears", 789622));
        data.add(new ValueDataEntry("Bananas", 7216301));
        data.add(new ValueDataEntry("Grapes", 1486621));
        data.add(new ValueDataEntry("Oranges", 1200000));

        pie.data(data);
        anyChartView.setChart(pie);
        pie.draw(true); //This line is not in their example, but still not show Pie chart with or without it.
    }

I could NOT see anywhere I can do to make it work. The documentation is so limited and inaccurate. Searching in web results no helpful answers either in last a few days. Any hints will be highly appreciated!

Thanks in advance.

1

There are 1 best solutions below

0
Shawn On

it looks like I have to set absolute height like this:

 <LinearLayout
    android:id="@+id/chart_layout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dimen_200dp"
    android:orientation="vertical"
    android:visibility="gone">

      <com.anychart.AnyChartView
          android:id="@+id/anyChartView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/>
  </LinearLayout>

though the layout file is still blank, but Pie Chart appears when running the app.