activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.graphs.graphs2.MainActivity">
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
InsightActivity.java
package com.animedix.health_hive.buzz.insights;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.animedix.health_hive.R;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
public class InsightsActivity extends Activity {
TextView Firstday, Secondday, Thirdday, Fourthday, Fifthday, SixthDay, Seventhday,
Firstdate, Seconddate, Thirddate, Fourthdate, Fifthdate, SixthDate, Seventhdate,tool_title;
Toolbar toolbar_insight;
ImageView img_back;
Calendar Todaydate;
HorizontalBarChart barChart,second_barchart,third_barchart,fourth_barchart,fifth_barchart,sixth_barchart,seventh_barchart;
ArrayList<BarEntry> bargroup1,bargroup2,bargroup3,bargroup4,bargroup5,bargroup6,bargroup7;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insight);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String formattedDate = df.format(c.getTime());
Log.e("today","today "+formattedDate);
toolbar_insight = (Toolbar) findViewById(R.id.toolbar_insight);
img_back = (ImageView) toolbar_insight.findViewById(R.id.img_back);
Firstday = (TextView) findViewById(R.id.txt_first_day);
Secondday = (TextView) findViewById(R.id.txt_second_day);
Thirdday = (TextView) findViewById(R.id.txt_third_day);
Fourthday = (TextView) findViewById(R.id.txt_fourth_day);
Fifthday = (TextView) findViewById(R.id.txt_fifth_day);
SixthDay = (TextView) findViewById(R.id.txt_sixth_day);
Seventhday = (TextView) findViewById(R.id.txt_seventh_day);
Firstdate = (TextView) findViewById(R.id.txt_first_date);
Seconddate = (TextView) findViewById(R.id.txt_second_date);
Thirddate = (TextView) findViewById(R.id.txt_third_date);
Fourthdate = (TextView) findViewById(R.id.txt_fourth_date);
Fifthdate = (TextView) findViewById(R.id.txt_fifth_date);
SixthDate = (TextView) findViewById(R.id.txt_sixth_date);
Seventhdate = (TextView) findViewById(R.id.txt_seventh_date);
tool_title = (TextView) toolbar_insight.findViewById(R.id.txt_careteam);
tool_title.setText("The Buzz");
tool_title.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
img_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date myDate = null;
try {
myDate = dateFormat.parse(formattedDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar.setTime(myDate);
calendar.add(Calendar.DAY_OF_YEAR, -7);
Calendar calendar1 = Calendar.getInstance();
SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date myDate1 = null;
try {
myDate1 = dateFormat1.parse(formattedDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar1.setTime(myDate1);
calendar1.add(Calendar.DAY_OF_YEAR, -6);
Calendar calendar2 = Calendar.getInstance();
SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date myDate2 = null;
try {
myDate2 = dateFormat2.parse(formattedDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar2.setTime(myDate2);
calendar2.add(Calendar.DAY_OF_YEAR, -5);
Calendar calendar3 = Calendar.getInstance();
SimpleDateFormat dateFormat3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date myDate3 = null;
try {
myDate3 = dateFormat3.parse(formattedDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar3.setTime(myDate3);
calendar3.add(Calendar.DAY_OF_YEAR, -4);
Calendar calendar4 = Calendar.getInstance();
SimpleDateFormat dateFormat4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date myDate4 = null;
try {
myDate4 = dateFormat4.parse(formattedDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar4.setTime(myDate4);
calendar4.add(Calendar.DAY_OF_YEAR, -3);
Calendar calendar5 = Calendar.getInstance();
SimpleDateFormat dateFormat5 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date myDate5 = null;
try {
myDate5 = dateFormat5.parse(formattedDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar5.setTime(myDate5);
calendar5.add(Calendar.DAY_OF_YEAR, -2);
Calendar calendar6 = Calendar.getInstance();
SimpleDateFormat dateFormat6 = new SimpleDateFormat("yyyy-MM-dd");
Date myDate6 = null;
try {
myDate6 = dateFormat6.parse(formattedDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar6.setTime(myDate6);
calendar6.add(Calendar.DAY_OF_YEAR, -1);
Date newDate = calendar.getTime();
Date newDate1 = calendar1.getTime();
Date newDate2 = calendar2.getTime();
Date newDate3 = calendar3.getTime();
Date newDate4 = calendar4.getTime();
Date newDate5 = calendar5.getTime();
Date newDate6 = calendar6.getTime();
Log.e("test", "test" + newDate.toString());
Log.e("test", "test" + newDate1.toString());
Log.e("test", "test" + newDate2.toString());
Log.e("test", "test" + newDate3.toString());
Log.e("test", "test" + newDate4.toString());
Log.e("test", "test" + newDate5.toString());
Log.e("test", "test" + newDate6.toString());
Log.e("substring",newDate.toString().substring(0, Math.min(newDate.toString().length(), 10)));
String date=newDate.toString().substring(0, Math.min(newDate.toString().length(), 10));
String date1=newDate1.toString().substring(0, Math.min(newDate1.toString().length(), 10));
String date2=newDate2.toString().substring(0, Math.min(newDate2.toString().length(), 10));
String date3=newDate3.toString().substring(0, Math.min(newDate3.toString().length(), 10));
String date4=newDate4.toString().substring(0, Math.min(newDate4.toString().length(), 10));
String date5=newDate5.toString().substring(0, Math.min(newDate5.toString().length(), 10));
String date6=newDate6.toString().substring(0, Math.min(newDate6.toString().length(), 10));
String[] day = date.split(" ");
String[] day1 = date1.split(" ");
String[] day2 = date2.split(" ");
String[] day3 = date3.split(" ");
String[] day4 = date4.split(" ");
String[] day5 = date5.split(" ");
String[] day6 = date6.split(" ");
Firstday.setText(day[0]);
Firstdate.setText(day[2] + "/" +day[1]);
Secondday.setText(day1[0]);
Seconddate.setText(day1[2] + "/" +day[1]);
Thirdday.setText(day2[0]);
Thirddate.setText(day2[2] + "/" +day[1]);
Fourthday.setText(day3[0]);
Fourthdate.setText(day3[2] + "/" +day[1]);
Fifthday.setText(day4[0]);
Fifthdate.setText(day4[2] + "/" +day[1]);
SixthDay.setText(day5[0]);
SixthDate.setText(day5[2] + "/" +day[1]);
Seventhday.setText(day6[0]);
Seventhdate.setText(day6[2] + "/" +day[1]);
barChart = (HorizontalBarChart) findViewById(R.id.barchart);
second_barchart = (HorizontalBarChart) findViewById(R.id.second_barchart);
third_barchart = (HorizontalBarChart) findViewById(R.id.third_barchart);
fourth_barchart = (HorizontalBarChart) findViewById(R.id.fourth_barchart);
fifth_barchart = (HorizontalBarChart) findViewById(R.id.fifth_barchart);
sixth_barchart = (HorizontalBarChart) findViewById(R.id.sixth_barchart);
seventh_barchart = (HorizontalBarChart) findViewById(R.id.seventh_barchart);
ArrayList<BarEntry> bargroup1 = new ArrayList<>();
bargroup1.add(new BarEntry(18f, 0));
bargroup1.add(new BarEntry(28f, 1));
bargroup1.add(new BarEntry(18f, 2));
bargroup1.add(new BarEntry(48f, 3));
ArrayList<BarEntry> bargroup2 = new ArrayList<>();
bargroup2.add(new BarEntry(6f, 0));
ArrayList<BarEntry> bargroup3 = new ArrayList<>();
bargroup3.add(new BarEntry(9f, 0));
ArrayList<BarEntry> bargroup4 = new ArrayList<>();
bargroup4.add(new BarEntry(16f, 0));
ArrayList<BarEntry> bargroup5 = new ArrayList<>();
bargroup5.add(new BarEntry(26f, 0));
ArrayList<BarEntry> bargroup6 = new ArrayList<>();
bargroup6.add(new BarEntry(36f, 0));
ArrayList<BarEntry> bargroup7 = new ArrayList<>();
bargroup7.add(new BarEntry(46f, 0));
BarDataSet barDataSet1 = new BarDataSet(bargroup1, "");
barDataSet1.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet2 = new BarDataSet(bargroup2, "");
barDataSet2.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet3 = new BarDataSet(bargroup3, "");
barDataSet3.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet4 = new BarDataSet(bargroup4, "");
barDataSet4.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet5 = new BarDataSet(bargroup5, "");
barDataSet5.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet6 = new BarDataSet(bargroup6, "");
barDataSet6.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet7 = new BarDataSet(bargroup7, "");
barDataSet7.setColors(ColorTemplate.COLORFUL_COLORS);
ArrayList<String> labels = new ArrayList<String>();
labels.add("");
labels.add("");
labels.add("");
labels.add("");
ArrayList<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add(barDataSet1);
BarData data = new BarData(labels, dataSets);
barChart.setData(data);
ArrayList<IBarDataSet> dataSets1 = new ArrayList<>();
dataSets1.add(barDataSet2);
BarData data1 = new BarData(labels, dataSets1);
second_barchart.setData(data1);
ArrayList<IBarDataSet> dataSets2 = new ArrayList<>();
dataSets2.add(barDataSet3);
BarData data2 = new BarData(labels, dataSets2);
third_barchart.setData(data2);
ArrayList<IBarDataSet> dataSets3 = new ArrayList<>();
dataSets3.add(barDataSet4);
BarData data3 = new BarData(labels, dataSets3);
fourth_barchart.setData(data3);
ArrayList<IBarDataSet> dataSets4 = new ArrayList<>();
dataSets4.add(barDataSet5);
BarData data4 = new BarData(labels, dataSets4);
fifth_barchart.setData(data4);
ArrayList<IBarDataSet> dataSets5 = new ArrayList<>();
dataSets5.add(barDataSet6);
BarData data5 = new BarData(labels, dataSets5);
sixth_barchart.setData(data5);
ArrayList<IBarDataSet> dataSets6 = new ArrayList<>();
dataSets6.add(barDataSet6);
BarData data6 = new BarData(labels, dataSets6);
seventh_barchart.setData(data6);
barChart.animateY(3000);
second_barchart.animateY(3000);
third_barchart.animateY(3000);
fourth_barchart.animateY(3000);
fifth_barchart.animateY(3000);
sixth_barchart.animateY(3000);
seventh_barchart.animateY(3000);
barChart.getXAxis().setDrawGridLines(false);
barChart.getXAxis().setDrawAxisLine(false);
barChart.getDrawingCache(false);
barChart.getAxisLeft().setDrawTopYLabelEntry(false);
barChart.getAxisLeft().setDrawTopYLabelEntry(false);
barChart.getAxisLeft().setDrawLimitLinesBehindData(false);
barChart.getAxisLeft().setDrawAxisLine(false);
barChart.getAxisLeft().setDrawZeroLine(false);
barChart.getAxisLeft().setDrawGridLines(false);
barChart.getAxisRight().setDrawZeroLine(false);
barChart.getAxisRight().setDrawLimitLinesBehindData(false);
barChart.getAxisRight().setDrawAxisLine(false);
barChart.getAxisRight().setDrawGridLines(false);
barChart.getAxisRight().setDrawTopYLabelEntry(false);
second_barchart.getXAxis().setDrawGridLines(false);
second_barchart.getXAxis().setDrawAxisLine(false);
second_barchart.getDrawingCache(false);
second_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
second_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
second_barchart.getAxisLeft().setDrawLimitLinesBehindData(false);
second_barchart.getAxisLeft().setDrawAxisLine(false);
second_barchart.getAxisLeft().setDrawZeroLine(false);
second_barchart.getAxisLeft().setDrawGridLines(false);
second_barchart.getAxisRight().setDrawZeroLine(false);
second_barchart.getAxisRight().setDrawLimitLinesBehindData(false);
second_barchart.getAxisRight().setDrawAxisLine(false);
second_barchart.getAxisRight().setDrawGridLines(false);
second_barchart.getAxisRight().setDrawTopYLabelEntry(false);
third_barchart.getXAxis().setDrawGridLines(false);
third_barchart.getXAxis().setDrawAxisLine(false);
third_barchart.getDrawingCache(false);
third_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
third_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
third_barchart.getAxisLeft().setDrawLimitLinesBehindData(false);
third_barchart.getAxisLeft().setDrawAxisLine(false);
third_barchart.getAxisLeft().setDrawZeroLine(false);
third_barchart.getAxisLeft().setDrawGridLines(false);
third_barchart.getAxisRight().setDrawZeroLine(false);
third_barchart.getAxisRight().setDrawLimitLinesBehindData(false);
third_barchart.getAxisRight().setDrawAxisLine(false);
third_barchart.getAxisRight().setDrawGridLines(false);
third_barchart.getAxisRight().setDrawTopYLabelEntry(false);
fourth_barchart.getXAxis().setDrawGridLines(false);
fourth_barchart.getXAxis().setDrawAxisLine(false);
fourth_barchart.getDrawingCache(false);
fourth_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
fourth_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
fourth_barchart.getAxisLeft().setDrawLimitLinesBehindData(false);
fourth_barchart.getAxisLeft().setDrawAxisLine(false);
fourth_barchart.getAxisLeft().setDrawZeroLine(false);
fourth_barchart.getAxisLeft().setDrawGridLines(false);
fourth_barchart.getAxisRight().setDrawZeroLine(false);
fourth_barchart.getAxisRight().setDrawLimitLinesBehindData(false);
fourth_barchart.getAxisRight().setDrawAxisLine(false);
fourth_barchart.getAxisRight().setDrawGridLines(false);
fourth_barchart.getAxisRight().setDrawTopYLabelEntry(false);
fifth_barchart.getXAxis().setDrawGridLines(false);
fifth_barchart.getXAxis().setDrawAxisLine(false);
fifth_barchart.getDrawingCache(false);
fifth_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
fifth_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
fifth_barchart.getAxisLeft().setDrawLimitLinesBehindData(false);
fifth_barchart.getAxisLeft().setDrawAxisLine(false);
fifth_barchart.getAxisLeft().setDrawZeroLine(false);
fifth_barchart.getAxisLeft().setDrawGridLines(false);
fifth_barchart.getAxisRight().setDrawZeroLine(false);
fifth_barchart.getAxisRight().setDrawLimitLinesBehindData(false);
fifth_barchart.getAxisRight().setDrawAxisLine(false);
fifth_barchart.getAxisRight().setDrawGridLines(false);
fifth_barchart.getAxisRight().setDrawTopYLabelEntry(false);
sixth_barchart.getXAxis().setDrawGridLines(false);
sixth_barchart.getXAxis().setDrawAxisLine(false);
sixth_barchart.getDrawingCache(false);
sixth_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
sixth_barchart.getAxisLeft().setDrawLimitLinesBehindData(false);
sixth_barchart.getAxisLeft().setDrawAxisLine(false);
sixth_barchart.getAxisLeft().setDrawZeroLine(false);
sixth_barchart.getAxisLeft().setDrawGridLines(false);
sixth_barchart.getAxisRight().setDrawZeroLine(false);
sixth_barchart.getAxisRight().setDrawLimitLinesBehindData(false);
sixth_barchart.getAxisRight().setDrawAxisLine(false);
sixth_barchart.getAxisRight().setDrawGridLines(false);
sixth_barchart.getAxisRight().setDrawTopYLabelEntry(false);
seventh_barchart.getXAxis().setDrawGridLines(false);
seventh_barchart.getXAxis().setDrawAxisLine(false);
seventh_barchart.getDrawingCache(false);
seventh_barchart.getAxisLeft().setDrawTopYLabelEntry(false);
seventh_barchart.getAxisLeft().setDrawLimitLinesBehindData(false);
seventh_barchart.getAxisLeft().setDrawAxisLine(false);
seventh_barchart.getAxisLeft().setDrawZeroLine(false);
seventh_barchart.getAxisLeft().setDrawGridLines(false);
seventh_barchart.getAxisRight().setDrawZeroLine(false);
seventh_barchart.getAxisRight().setDrawLimitLinesBehindData(false);
seventh_barchart.getAxisRight().setDrawAxisLine(false);
seventh_barchart.getAxisRight().setDrawGridLines(false);
seventh_barchart.getAxisRight().setDrawTopYLabelEntry(false);
}
}
[I need to remove top & below entry of the chart 10,20,30 & remove description in Chart..][1]
[1]: https: