Comments (5)
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.
HI @PhilJay,
Thanks for your update. I have implemented it and it is working properly. After implementing I found the following observation-
- Swipe left for the BarChart is not working. If I do a leftswipe on chart it is not swiping. Picture as attached.
- **Is It possible to hide the grids as instructed?
Thanks in advance!!
from mpandroidchart.
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.
Hi @PhilJay ,
I did it and it looks like below.
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.
@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)
- combined chart issue
- Update repository
- Animate only selected bars in BarChartSelectable
- Android Studio: disabled warning when using SDK features unavailable at SDK 21 (e.g. @FunctionalInterface or streaming)? HOT 1
- Barchart is not displaying properly for 15 days. HOT 2
- Granularity is not working when set to 6f.
- Highlight issues after i applied RoundedSlicesPieChartRenderer in piechart
- 可以设置初始化Y轴数据的数量 之后一个一个的动态加载吗?
- Help: Dotted Background
- 使用implementation ("com.github.PhilJay:MPAndroidChart:v3.0.2")报错
- Values above the Horizontal bars Disappears when I zoomed in
- dataSet.gradientColors = gradientColors not working
- Fatal Exception: java.lang.NegativeArraySizeException HOT 4
- LineDataSet: shader with multiple color
- Getting crash while selection camera cropping only in Android 10
- How to rotate the Tooltip arrow Based on the touch points
- Documentation Link Failed! HOT 4
- When drawing Bezier curves vertically in LineChart, the curve flickers.
- Fatal Exception: java.lang.NullPointerException Attempt to read from null array
- Fatal Exception: java.lang.ArrayIndexOutOfBoundsException
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpandroidchart.