我想创建包含一格和n线图的组合图。我做的。当我单击折线图时,我可以看到它们的值,但是当它在条形图上方时,条形值不会显示。您可以在下面看到我的图表:
左侧大约是条形,右侧大约是线。当我单击第二个栏内的任意位置时,它会显示行值。我该如何解决?
private void DoubleChartOlustur(int index) {
CombinedChart combinedChart = new CombinedChart(getActivity());
combinedChart.getDescription().setEnabled(false);
combinedChart.setDrawGridBackground(false);
combinedChart.setDrawBarShadow(false);
combinedChart.setHighlightFullBarEnabled(false);
String[] legend = Global.menuListesi.get(index).getLejantlar().split(",");
CombinedData data = new CombinedData();
LineData lineData = new LineData();
ArrayList<BarEntry> entries = new ArrayList<>();
if(Global.x1.size() > 0){
for (int i = 0; i < Global.x1.size(); i++) {
entries.add(new BarEntry(i, Float.valueOf(Global.x1.get(i)), new BigDecimal(Global.x1.get(i))));
}
final BarDataSet dataset = new BarDataSet(entries, legend[0]);
dataset.setColor(tempRenkSeti[0]);
dataset.setAxisDependency(YAxis.AxisDependency.LEFT);
BarData barData = new BarData(dataset);
data.setData(barData);
}
if (Global.x2.size() > 0) {
ArrayList<Entry> entries2 = new ArrayList<>();
for (int i = 0; i < Global.x2.size(); i++) {
entries2.add(new Entry(i, Float.valueOf(Global.x2.get(i)), new BigDecimal(Global.x2.get(i))));
}
LineDataSet dataset2 = new LineDataSet(entries2, legend[1]);
dataset2.setColor(tempRenkSeti[1]);
dataset2.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset2);
data.setData(lineData);
}
if (Global.x3.size() > 0) {
ArrayList<Entry> entries3 = new ArrayList<>();
for (int i = 0; i < Global.x3.size(); i++) {
entries3.add(new Entry(i, Float.valueOf(Global.x3.get(i)), new BigDecimal(Global.x3.get(i))));
}
LineDataSet dataset3 = new LineDataSet(entries3, legend[2]);
dataset3.setColor(tempRenkSeti[2]);
dataset3.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset3);
data.setData(lineData);
}
if (Global.x4.size() > 0) {
ArrayList<Entry> entries4 = new ArrayList<>();
for (int i = 0; i < Global.x4.size(); i++) {
entries4.add(new Entry(i, Float.valueOf(Global.x4.get(i)), new BigDecimal(Global.x4.get(i))));
}
LineDataSet dataset4 = new LineDataSet(entries4, legend[3]);
dataset4.setColor(tempRenkSeti[3]);
dataset4.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset4);
data.setData(lineData);
}
if (Global.x5.size() > 0) {
ArrayList<Entry> entries5 = new ArrayList<>();
for (int i = 0; i < Global.x5.size(); i++) {
entries5.add(new Entry(i, Float.valueOf(Global.x5.get(i)), new BigDecimal(Global.x5.get(i))));
}
LineDataSet dataset5 = new LineDataSet(entries5, legend[4]);
dataset5.setColor(tempRenkSeti[4]);
dataset5.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset5);
data.setData(lineData);
}
if (Global.x6.size() > 0) {
ArrayList<Entry> entries6 = new ArrayList<>();
for (int i = 0; i < Global.x6.size(); i++) {
entries6.add(new Entry(i, Float.valueOf(Global.x6.get(i)), new BigDecimal(Global.x6.get(i))));
}
LineDataSet dataset6 = new LineDataSet(entries6, legend[5]);
dataset6.setColor(tempRenkSeti[0]);
dataset6.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset6);
data.setData(lineData);
}
if (Global.x7.size() > 0) {
ArrayList<Entry> entries7 = new ArrayList<>();
for (int i = 0; i < Global.x7.size(); i++) {
entries7.add(new Entry(i, Float.valueOf(Global.x7.get(i)), new BigDecimal(Global.x7.get(i))));
}
LineDataSet dataset7 = new LineDataSet(entries7, legend[6]);
dataset7.setColor(tempRenkSeti[1]);
dataset7.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset7);
data.setData(lineData);
}
if (Global.x8.size() > 0) {
ArrayList<Entry> entries8 = new ArrayList<>();
for (int i = 0; i < Global.x8.size(); i++) {
entries8.add(new Entry(i, Float.valueOf(Global.x8.get(i)), new BigDecimal(Global.x8.get(i))));
}
LineDataSet dataset8 = new LineDataSet(entries8, legend[7]);
dataset8.setColor(tempRenkSeti[2]);
dataset8.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset8);
data.setData(lineData);
}
if (Global.x9.size() > 0) {
ArrayList<Entry> entries9 = new ArrayList<>();
for (int i = 0; i < Global.x9.size(); i++) {
entries9.add(new Entry(i, Float.valueOf(Global.x9.get(i)), new BigDecimal(Global.x9.get(i))));
}
LineDataSet dataset9 = new LineDataSet(entries9, legend[8]);
dataset9.setColor(tempRenkSeti[3]);
dataset9.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset9);
data.setData(lineData);
}
if (Global.x10.size() > 0) {
ArrayList<Entry> entries10 = new ArrayList<>();
for (int i = 0; i < Global.x10.size(); i++) {
entries10.add(new Entry(i, Float.valueOf(Global.x10.get(i)), new BigDecimal(Global.x10.get(i))));
}
LineDataSet dataset10 = new LineDataSet(entries10, legend[9]);
dataset10.setColor(tempRenkSeti[4]);
dataset10.setAxisDependency(YAxis.AxisDependency.RIGHT);
lineData.addDataSet(dataset10);
data.setData(lineData);
}
if(entries.size() > 0){
combinedChart.setData(data);
}
Legend l = combinedChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setXEntrySpace(7f);
l.setYEntrySpace(0f);
l.setYOffset(5f);
l.setWordWrapEnabled(true);
combinedChart.animateY(3000);
XAxis xAxis = combinedChart.getXAxis();
xAxis.setGranularityEnabled(true);
xAxis.setAvoidFirstLastClipping(true);
xAxis.setGranularity(1f);
xAxis.setSpaceMin(0.5f);
xAxis.setSpaceMax(0.5f);
xAxis.setDrawGridLines(false);
xAxis.setValueFormatter(new IndexAxisValueFormatter(Global.xTitle));
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setLabelRotationAngle(45);
xAxis.setLabelCount(Global.xTitle.size());
xAxis.setEnabled(false);
YAxis rightYAxis = combinedChart.getAxisRight();
rightYAxis.setEnabled(true);
rightYAxis.setDrawGridLines(false);
rightYAxis.setAxisMinimum(0f);
combinedChart.setDoubleTapToZoomEnabled(false);
combinedChart.getAxisLeft().setAxisMinimum(0f);
combinedChart.setPinchZoom(false);
ChartMarkerView mv = new ChartMarkerView(getActivity(), R.layout.marker_view_content, ((IndexAxisValueFormatter)combinedChart.getXAxis().getValueFormatter()).getValues());
combinedChart.setMarker(mv);
combinedChart.setNoDataText("Aradığınız kriterde herhangi bir veri bulunamadı");
//Konfigürasyonlar
data.setDrawValues(false); // Grafik değerlerini kapat
data.setValueFormatter(new LargeValueFormatter());
if(Global.xTitle.size() > 10){
combinedChart.setVisibleXRangeMaximum(10);
}
combinedChart.invalidate();
combinedChart.notifyDataSetChanged();
}
对不起,我很抱歉。