AnimatedPieView is a simple and easy-to-use pie-chart view.
- Fix the problem of losing data when the animation is too fast
- Fix the problem that the pie chart does not respond when clicked under special data.
- Fixed Bugs:
Develop Plan (Update Log->Update Log)
No plan now....I'm eagerly waiting for your great suggestions.
Support typeface for label #26Support tap label to select pie #27Support legendsSupport label for description textProject Optimization and Reconstruction, version 1.2.0 releaseSupport alpha to highlight the selected pieSupport the pies to have a space between themTextField adapt animation position changedText Line show animationClick callbackClick effectSupport click for every pieSupport transform between pie-chart and ring-chartSupport animation drawing
Use in gradle(please replace {latestVersion} to the download badge version)
dependencies {
implementation 'com.github.razerdp:AnimatedPieView:{latestVersion}'
}
step 1:Define any class to implement the IPieInfo interface(you can also use SimplePieInfo)
public class Test implements IPieInfo {
@Override
public float getValue() {
// This return value will determine the percentage
return 0.5f;
}
@Override
public int getColor() {
// This return value will determine the cur-pie color,please return @colorInt,but not @colorRes
return Color.WHITE;
}
@Override
public String getDesc() {
// description text, may not return
return "这是一个测试";
}
@Nullable
@Override
public PieOption getPieOpeion() {
// option for pie,example: descript label
return mPieOption;
}
}
step 2:New AnimatedPieViewConfig and configure it
AnimatedPieView mAnimatedPieView = findViewById(R.id.animatedPieView);
AnimatedPieViewConfig config = new AnimatedPieViewConfig();
config.startAngle(-90)// Starting angle offset
.addData(new SimplePieInfo(30, getColor("FFC5FF8C"), "这是第一段"))//Data (bean that implements the IPieInfo interface)
.addData(new SimplePieInfo(18.0f, getColor("FFFFD28C"), "这是第二段"))
...(addData so on)
.duration(2000);// draw pie animation duration
// The following two sentences can be replace directly 'mAnimatedPieView.start (config); '
mAnimatedPieView.applyConfig(config);
mAnimatedPieView.start();
AnimatedPieViewConfig mConfig=mAnimatedPieView.getConfig();
mConfig.animOnTouch(true)// Animation when selected pie(default:true)
.addData(IPieInfo info, boolean autoDesc)// Add data (bean that implements the IPieInfo interface).autoDesc:automatically add description(e.g. 8.8%)
.floatExpandAngle(15f)// Selected pie's angle of expansion
.floatShadowRadius(18f)// Selected pie's shadow of expansion
.floatUpDuration(500)// Selected pie's floating animation duration
.floatDownDuration(500)// Last selected pie's float down animation duration
.floatExpandSize(15)// Selected pie's size of expansion(only for pie-chart,not ring-chart)
.strokeMode(true)// Whether to draw ring-chart(default:true)
.strokeWidth(15)// Stroke width for ring-chart
.duration(2500)// Animation drawing duration
.startAngle(-90f)// Starting angle offset
.selectListener(new OnPieSelectListener<IPieInfo>())// Click callback
.drawText(true)// Whether to draw a text description
.textSize(12)// Text description size
.textMargin(8)// Margin between text and guide line
.autoSize(true)// Auto fit chart radius
.pieRadius(100)// Set chart radius
.pieRadiusRatio(0.8f)// Chart's radius ratio for parent ViewGroup
.guidePointRadius(2)// Chart's radius
.guideLineWidth(4)// Text guide line stroke width
.guideLineMarginStart(8)// Guide point margin from chart
.textGravity(AnimatedPieViewConfig.ABOVE)// Text Gravity 【
-AnimatedPieViewConfig.ABOVE:Text will be drawn above the guide line
-AnimatedPieViewConfig.BELOW:Text will be drawn below the guide line
-AnimatedPieViewConfig.ALIGN:Text will be drawn align to the guide line
-AnimatedPieViewConfig.ECTOPIC:Text will be drawn above the line in the 1, 2 quadrants and below the line in the 3, 4 quadrants
】
.canTouch(true)// Whether to allow the pie click to enlarge
.typeFae(TypeFace)// Typeface of desc
.splitAngle(1)// Clearance angle
.focusAlphaType(AnimatedPieViewConfig.FOCUS_WITH_ALPHA_REV)// Alpha change mode for selected pie
.interpolator(new DecelerateInterpolator())// Set animation interpolator
.focusAlpha(150) // Alpha for selected pie (depend on focusAlphaType)
.legendsWith((ViewGroup) findViewById(R.id.ll_legends), new OnPieLegendBindListener<BasePieLegendsView>() {
@Override
public BasePieLegendsView onCreateLegendView(int position, IPieInfo info) {
return position % 2 == 0 ?
DefaultPieLegendsView.newInstance(MainActivity.this)
: DefaultCirclePieLegendsView.newInstance(MainActivity.this);
}
@Override
public boolean onAddView(ViewGroup parent, BasePieLegendsView view) {
return false;
}
}); // Set a legends container to bind legends views
you can decide your pie with create PieOption
// IPieInfo.java#getPieOption()
@Nullable
@Override
public PieOption getPieOption() {
return new PieOption()
.setDefaultSelected(true) // Selected this pie by default
.setIconHeight(50) // Text icon height
.setIconWidth(50) // Text icon width
.setIconScaledHeight(0.5f) // Text icon height scaling
.setIconScaledWidth(0.5f) // Text icon width scaling
.setLabelIcon(bitmap) // Text icon bitmap resource
.setLabelPadding(5) // Icon and text distance
.setLabelPosition(PieOption.NEAR_PIE); // Decide which position of the icon in the pie
}
AliPay | |
---|---|
Apache-2.0
This project exists thanks to all the people who contribute.
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]