堆叠条形图的工具提示使用MarkerView&传说中的问题

时间:2015-02-25 11:20:41

标签: android mpandroidchart

我想在我的Android应用程序中使用工具提示功能显示堆积条形图。我用MarkerView显示它但没有成功。这是示例代码。

此外,我在传奇中遇到问题......! 由于图书馆不支持文本换行,因此图例不会显示。 并且Y轴上的值显示在整数中。我希望在Floats中显示。我可以在Y轴值中给出'%'吗?像这样的东西,

https://drive.google.com/a/findabilitysciences.com/file/d/0B-kRufrwei7wSHFMQjVDMkdTNVk/view?usp=sharing

        chart1 = (BarChart) findViewById(R.id.chart1);
                    chart1.setDrawYValues(true);
                    //chart1.setDrawValueAboveBar(true);
                    chart1.setDescription("");
                    chart1.set3DEnabled(false);
                    chart1.setUnit("%");
                    chart1.setDrawGridBackground(false);
                    chart1.setDrawHorizontalGrid(true);
                    chart1.setValueTextSize(8f);
                    chart1.setDrawBorder(false);
                    chart1.setYRange(0.0f,100.0f,true);
                    chart1.setDrawLegend(true);
                    chart1.setPinchZoom(true);
                    chart1.setTouchEnabled(true);
                    //Code for Tooltip at barchart.
                    /*MyMarkerView mv = new MyMarkerView(getApplicationContext(), R.layout.custom_marker_view);
                    mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
                    chart1.setMarkerView(mv);*/






                    XLabels xl = chart1.getXLabels();
                    xl.setPosition(XLabels.XLabelPosition.BOTTOM);
                    xl.setSpaceBetweenLabels(10);
                    xl.setCenterXLabelText(true);

                    YLabels yl = chart1.getYLabels();
                    //yl.setLabelCount(10);
                    yl.setPosition(YLabels.YLabelPosition.LEFT);


                    setData();

                    Legend l = chart1.getLegend();
                    l.setPosition(Legend.LegendPosition.BELOW_CHART_RIGHT);
                    l.setFormSize(8f);
                    l.setYEntrySpace(4f);

                    chart1.animateY(3000);


                }


            } catch (JSONException e) {
                // TODO Auto-generated catch block
                Toast.makeText(getApplicationContext(), "Error Occurred [Server's JSON response might be invalid]!" + e.getMessage(), Toast.LENGTH_LONG).show();
                e.printStackTrace();

            }

        }

        private void setData() {
            ArrayList<String> xVals = new <String>ArrayList<String>();
            xVals.add("Donors");
            xVals.add("Amount");

            ArrayList<BarEntry> yVals1 = new <BarEntry>ArrayList<BarEntry>();

            yVals1.add(new BarEntry(new float[]{donoravg.get(0),donoravg.get(1),donoravg.get(2),donoravg.get(3),donoravg.get(4),donoravg.get(5),donoravg.get(6),donoravg.get(7),donoravg.get(8),donoravg.get(9),donoravg.get(10)}, 0));
            yVals1.add(new BarEntry(new float[]{amountavg.get(0),amountavg.get(1),amountavg.get(2),amountavg.get(3),amountavg.get(4),amountavg.get(5),amountavg.get(6),amountavg.get(7),amountavg.get(8),amountavg.get(9)}, 1));

            BarDataSet set1 = new BarDataSet(yVals1, "");
            set1.setStackLabels(new String[]{"All other defector count", "Last Year Defector Count", "At Risk Donor Count"});
            set1.setBarSpacePercent(40f);
            set1.setColors(new int[]{R.color.pink_400, R.color.purple_300, R.color.deep_purple_300, R.color.indigo_300, R.color.cyan_300, R.color.teal_300, R.color.amber_300, R.color.deep_orange_300, R.color.brown_300, R.color.blue_grey_300}, getApplicationContext());

            ArrayList<BarDataSet> dataSets = new <BarDataSet>ArrayList<BarDataSet>();
            dataSets.add(set1);
            BarData data = new BarData(xVals, dataSets);
            chart1.setData(data);

        }

1 个答案:

答案 0 :(得分:0)

新的mpAndroidChart v2.0.7库解决了所有问题。 使用.setValueFormatter();我们可以格式化Y轴值和图表值。

对于传奇问题, 我没有显示Legends,而是添加了Touch Listener,它可以处理堆栈值。 触摸监听器可以显示有价值的细节。