I'll put the code on it for the time being (I'll write it clean later)
List<String> labels = new ArrayList<>();
List<BarEntry> bar = new ArrayList<>();
List<Entry> line = new ArrayList<>();
Random random = new Random();
for (int i=0; i<10; i++) {
//The label for the x-axis is List<String>
labels.add(String.valueOf(i));
//Each data is List<BarEntry>, List<Entry>Store in etc.
// Entry(float value, int index)
//A run-time error occurs if you specify an index longer than the length of labels
bar.add(new BarEntry((float)random.nextInt(10), i));
line.add(new Entry((float)random.nextInt(5)+3f, i));
}
//List of entries(List<Entry>)+ Name(String) => DataSet
//List of labels(List<String>) + DataSet => Data
//bar graph
BarDataSet barDataSet = new BarDataSet(bar, "bar");
BarData barData = new BarData(labels, barDataSet);
//Line graph
LineDataSet lineDataSet = new LineDataSet(line, "line");
lineDataSet.setColor(Color.BLACK);
lineDataSet.setLineWidth(1.5f);
lineDataSet.setDrawCircles(false);
LineData lineData = new LineData(labels, lineDataSet);
lineData.setDrawValues(false);
//combine
CombinedData data = new CombinedData(labels);
data.setData(lineData);
data.setData(barData);
chart.setData(data);
//chart
CombinedChart chart = (CombinedChart)findViewById(R.id.combined_chart);
chart.setBackgroundColor(Color.WHITE);
chart.setDrawGridBackground(false);
chart.setDrawBarShadow(false);
chart.setTouchEnabled(true);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
chart.setHighlightEnabled(false);
chart.setDescription("");
//x-axis setting
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setSpaceBetweenLabels(0);
//Right y-axis setting
chart.getAxisRight().setEnabled(false);
//animation
chart.invalidate();
chart.animateY(2000, Easing.EasingOption.EaseInBack);
Recommended Posts