【问题标题】:Navigation drawer with MPAndroidChart not working带有 MPAndroidChart 的导航抽屉不起作用
【发布时间】:2016-11-20 16:05:48
【问题描述】:

我正在使用 MPAndroidChart 来显示一些数据。我在不同的菜单选项上显示不同的图表。每个菜单选项调用一个片段。饼图显示正常,但导航切换不起作用。我在 LogCat 中没有收到任何错误。

下面是代码。

饼图片段 XML

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:id="@+id/mainLayout">



 <com.github.mikephil.charting.charts.PieChart
        android:id="@+id/chartPie"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

PieChartActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    try {

        root = (RelativeLayout) inflater.inflate(R.layout.fragment_piechart, container, false);

        getActivity().setContentView(R.layout.fragment_piechart);
        mainLayout = (RelativeLayout) root.findViewById(
                R.id.mainLayout);
        mChart = (PieChart) getActivity().findViewById(R.id.chartPie);
        // add pie chart to main layout
         //mainLayout.addView(mChart); 
        //mainLayout.setBackgroundColor(Color.parseColor("#55656C"));

        // configure pie chart
        mChart.setUsePercentValues(true);
        mChart.setDescription("OEE composition");

        // enable hole and configure
        mChart.setDrawHoleEnabled(true);
        //mChart.setHoleColor(Color.BLACK); 
        mChart.setHoleRadius(7);
        mChart.setTransparentCircleRadius(10);

        // enable rotation of the chart by touch
        mChart.setRotationAngle(0);
        mChart.setRotationEnabled(true);

        // set a chart value selected listener
        mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {

            @Override
            public void onValueSelected(Entry e, int dataSetIndex,
                    Highlight h) {
                // display msg when value selected
                if (e == null)
                    return;

                Toast.makeText(PieChartActivity.this.getActivity(),
                        xData[e.getXIndex()] + " = " + e.getVal() + "%",
                        Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected() {

            }
        });

        // customize legends
        Legend l = mChart.getLegend();
        l.setPosition(LegendPosition.RIGHT_OF_CHART);
        l.setXEntrySpace(7);
        l.setYEntrySpace(5);

    } catch (Exception ex) {
        Log.d("Error", ex.getMessage());
    }

    // Quality
    makeHTTPCall(objGlobal, "574c22cd7625423b05a2cbcc",
            prod_Count_UBI_link_QLTY);

    // Performance
    makeHTTPCall(objGlobal, "574c22ad76254239d6a6bc56",
            prod_Count_UBI_link_PERF);

    // Availability
    makeHTTPCall(objGlobal, "574c1e027625420f0e4401ff",
            prod_Count_UBI_link_AVAIL);

    return root;

}

PieChartActivity 扩展片段

 public class PieChartActivity extends Fragment implements
        OnChartValueSelectedListener

有趣的是,导航切换可以与不同片段上的其他图表一起正常工作。

如果需要更多详细信息,请告诉我。 我是 Android 新手,如果我在任何基础知识上错了,请告诉我...

【问题讨论】:

  • 抱歉详细说明,但只有滑动手势不起作用或在操作栏中切换?
  • 两者都不起作用...
  • 你能贴出完整的Fragment代码
  • 无法共享所有代码:(它有指向云的链接,我无法共享..
  • 您可以粘贴您的活动代码吗?

标签: android mpandroidchart


【解决方案1】:

将您的饼图布局放在@layout/app_bar_index 活动中。

【讨论】:

  • 我正在为您的帖子投票,这样您就可以尽快增加您的代表并在 cmets 中给出这些答案.. 好吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多