Giter Site home page Giter Site logo

Comments (5)

PhilJay avatar PhilJay commented on May 5, 2024

That's actually quite simple. When looking at your code, I see that you are mistaking a ListView for a ViewPager. While the demo-app displays BarCharts in a ListView, you want to use a ViewPager.

Here are the basics of what you need to do for using the chart in a ViewPager:

  • Create a Fragment that can display a BarChart, therefore you need a Fragment class, e.g. BarChartFragment:
public class BarChartFragment extends Fragment {

BarChart mChart;
BarData mData;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {       
        View v=inflater.inflate(R.layout.barchart_fragment,
            container, false);

        mChart = (BarChart) v.findViewById(R.id.chart1);
        mChart.setData(mData);
        return v;
      }
}

public void setData(BarData bd) {
    mData = bd;
}

And a .xml file that will be used as the layout for your fragment:

<?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" >

    <com.github.mikephil.charting.charts.BarChart
        android:id="@+id/chart1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

Inside your adaper, you can do it like this:

@Override
public Fragment getItem(int pos) {

     BarChartFragment f = null;    

     switch(pos) {
         case 0:
             f = new BarChartFragment();
             f.setData(yourData);
             break;

          case 1: // and so on
     }

     return f;
}

Thats about how it sould work.

Regards,
Phil

from mpandroidchart.

dasbiswajit avatar dasbiswajit commented on May 5, 2024

HI @PhilJay,
Thanks for your update. I have implemented it and it is working properly. After implementing I found the following observation-

  1. Swipe left for the BarChart is not working. If I do a leftswipe on chart it is not swiping. Picture as attached.
  2. **Is It possible to hide the grids as instructed?

screenshot_2014-08-25-17-39-47

Thanks in advance!!

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

The left swipe of the ViewPager is "disturbed" because of the chart lying on top.

If you dont need the chart to be touchable, set:

Chart.setTouchEnabled(false);

In that way swiping the ViewPager should work.

For hiding the grid, call

setDrawHorizontalGrid(false);
setDrawVerticalGrid(false);

from mpandroidchart.

dasbiswajit avatar dasbiswajit commented on May 5, 2024

Hi @PhilJay ,
I did it and it looks like below.
screenshot_2014-08-25-23-50-21

Since my screen is transparrent the chart should show with transparent background. SO that only Bars should be visable.
Is there any way to achieve this?
If I am giving
mChart.setBackgroundColor(Color.parseColor("#0D000000")); it is leaving a black border around the chart area. Else it is drawing white.

from mpandroidchart.

iad24 avatar iad24 commented on May 5, 2024

@PhilJay hi jay. great library btw. Just wondering if its a possible that user can scroll first the barchart. Then if theres nothing to scroll anymore, viewpager gets scrolled.

from mpandroidchart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.