How to draw Venn Diagram using AnyChart for Android

In this android programming source code example, we are going to draw Venn Diagram using AnyChart for Android.

You can copy and adopt this source code example to your android project without reinventing the wheel.

Below is a step by step source code to draw Venn Diagram using AnyChart for Android.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".AndroidChart.AndroidChartActivity13">

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

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.anychart.AnyChart;
import com.anychart.AnyChartView;
import com.anychart.chart.common.dataentry.DataEntry;
import com.anychart.chart.common.dataentry.NameValueDataEntry;
import com.anychart.charts.Venn;

import java.util.ArrayList;

public class AndroidChartActivity13 extends AppCompatActivity {
    private AnyChartView vennDiagramChart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_chart13);
        vennDiagramChart = (AnyChartView)findViewById(R.id.vennDiagramChart);
        vennDiagramChart.setProgressBar(findViewById(R.id.progress_bar));
        Venn venn = AnyChart.venn();
        venn.data(getData());
        venn.stroke("2 #FFFFFF");
        venn.labels().format("{%Name}");
        venn.intersections().hovered().fill("black", 0.25d);
        venn.intersections().labels().fontWeight("bold");
        venn.intersections().labels().format("{%Name}");
        venn.tooltip().titleFormat("{%Name}");
        vennDiagramChart.setChart(venn);
    }


    private ArrayList getData(){
        ArrayList<DataEntry> entries = new ArrayList<>();
        entries.add(new NameValueDataEntry("A", "English", 100));
        entries.add(new NameValueDataEntry("B", "Computer", 25));
        entries.add(new NameValueDataEntry("C", "Math", 25));
        entries.add(new NameValueDataEntry("D", "Geography", 25));
        entries.add(new NameValueDataEntry("A&B", "Computer", 50));
        entries.add(new NameValueDataEntry("A&C", "Math", 50));
        entries.add(new NameValueDataEntry("A&D", "Geography", 50));
        entries.add(new NameValueDataEntry("B&C", "History", 5));
        entries.add(new NameValueDataEntry("C&D", "Biology", 5));
        entries.add(new NameValueDataEntry("D&B", "Chemistry", 5));
        entries.add(new NameValueDataEntry("B&C&D", "Physics", 5));
        return entries;
    }
}

app/build.gradle

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

If you have any question or suggestions kindly use the comment box or you can contact us directly through our contact page below.

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.