RadarChart太大,无法从LinearLayout视图中删除图例

时间:2019-02-06 22:02:03

标签: android mpandroidchart

我正在将数据从Firebase用管道传输到RadarChart中,并且在这方面一切正常,但是,即使我指定了MATCH_PARENT,因此图例似乎被切断,生成的图表对于布局而言还是太大了,和几个xAxis标签一样。

我试图更改轴的最小值/最大值,但是这导致比例与数据不一致。

这是我的代码:


        mChartContainer.removeAllViewsInLayout(); // remove a previous chart
        mRadarChart = new RadarChart(this);
        LinearLayout.LayoutParams params = new 
        LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        params.weight = 1;
        mRadarChart.setLayoutParams(params);

        final String[] labels = new String[12];
        mMasterCategoriesRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if(dataSnapshot.exists()) {
                    for(DataSnapshot post : dataSnapshot.getChildren()) {
                        Category category = post.getValue(Category.class);
                        labels[category.getNumber()-1] = category.getName();
                        // category.getNumber() starts at 1, and we need it in position 0 to align with the start of the chart
                    }
                }
            }
            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });

        /**
         * Code to get allDataSets is here. It's long and irrelevant
         */

        RadarData data = new RadarData(allDataSets);
        data.setLabels(labels);
        // X-Axis
        XAxis xAxis = mRadarChart.getXAxis();
        xAxis.setAxisMinimum(0f);
        xAxis.setAxisMaximum(4f);
        xAxis.setPosition(XAxis.XAxisPosition.TOP);
        xAxis.setValueFormatter(new IAxisValueFormatter() {
            private String[] mLabels = labels;
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return mLabels[(int) value];
            }
        });

        // Y-Axis
        YAxis yAxis = mRadarChart.getYAxis();
        yAxis.setAxisMinimum(0f);
        yAxis.setAxisMaximum(4f);
        yAxis.setTextSize(11f);

        Legend legend = mRadarChart.getLegend();
        legend.setEnabled(true);
        legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        legend.setDrawInside(true);
        legend.setForm(Legend.LegendForm.SQUARE);
        legend.setFormSize(3f);
        legend.setTextSize(12f);
        legend.setXEntrySpace(8f);
        legend.setWordWrapEnabled(true);

        mRadarChart.animateXY(500, 500,
                Easing.EasingOption.EaseInOutQuad, Easing.EasingOption.EaseInOutQuad);
        mRadarChart.getDescription().setEnabled(false);
        mRadarChart.setData(data);
        mRadarChart.invalidate();

        mChartContainer.addView(mRadarChart);

bug

0 个答案:

没有答案