コード例 #1
0
  private void createPieChart() {
    mData.setHasLabels(true);
    mData.setHasLabelsOutside(false);
    mChart.setOnValueTouchListener(
        new PieChartOnValueSelectListener() {
          @Override
          public void onValueSelected(int i, SliceValue sliceValue) {
            Float convertValue = sliceValue.getValue() / Constants.SATOSHIS;
            String label = convertValue + " BTC";
            Toast.makeText(getApplicationContext(), label, Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onValueDeselected() {}
        });
    mChart.setZoomEnabled(true);
    mChart.setPieChartData(mData);
  }
コード例 #2
0
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_view_pager_charts, container, false);
      RelativeLayout layout = (RelativeLayout) rootView;
      int sectionNum = getArguments().getInt(ARG_SECTION_NUMBER);
      switch (sectionNum) {
        case 1:
          LineChartView lineChartView = new LineChartView(getActivity());
          lineChartView.setLineChartData(generateLineChartData());
          lineChartView.setZoomType(ZoomType.HORIZONTAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(lineChartView);
          break;
        case 2:
          ColumnChartView columnChartView = new ColumnChartView(getActivity());
          columnChartView.setColumnChartData(generateColumnChartData());
          columnChartView.setZoomType(ZoomType.HORIZONTAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          columnChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(columnChartView);
          break;
        case 3:
          BubbleChartView bubbleChartView = new BubbleChartView(getActivity());
          bubbleChartView.setBubbleChartData(generateBubbleChartData());
          bubbleChartView.setZoomType(ZoomType.HORIZONTAL_AND_VERTICAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          bubbleChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(bubbleChartView);
          break;
        case 4:
          PreviewLineChartView previewLineChartView = new PreviewLineChartView(getActivity());
          previewLineChartView.setLineChartData(generatePreviewLineChartData());

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          previewLineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          Viewport tempViewport = new Viewport(previewLineChartView.getMaximumViewport());
          float dx = tempViewport.width() / 6;
          tempViewport.inset(dx, 0);
          previewLineChartView.setCurrentViewport(tempViewport);
          previewLineChartView.setZoomType(ZoomType.HORIZONTAL);

          layout.addView(previewLineChartView);
          break;
        case 5:
          PieChartView pieChartView = new PieChartView(getActivity());
          pieChartView.setPieChartData(generatePieChartData());

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          pieChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(pieChartView);
          break;
      }

      return rootView;
    }