-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gives wrong touchedSectionIndex when value is 0 in PieChart #697
Comments
Hi. Thanks for reporting! Fixed in 0.36.2 |
Sorry to reporting again. Even though now it provides correct index but today I found that some section are not clickable. So for workaround manually filtering values with List<PieChartSectionData>? sections() {
return widget.chart.pieChartData
// // if value is 0, then section will not build
// // and gives wrong index on touch
// // https://github.com/imaNNeoFighT/fl_chart/issues/697
.where((element) => element.value != 0)
.toList()
.asMap()
.entries
.map(
(entry) {
final isTouched = entry.key == touchedIndex;
final fontSize = isTouched ? 18.0 : 16.0;
final radius = isTouched ? 135.0 : 130.0;
return PieChartSectionData(
color: AppColor.dashChartColors[entry.key],
value: entry.value.value.toDouble(),
title: '',
radius: radius,
badgeWidget: (isTouched && widget.tooltipBuilder != null)
? Container(
padding: const EdgeInsets.all(cTooltipPadding),
decoration: BoxDecoration(
color: cTooltipBgColor,
borderRadius: BorderRadius.circular(cTooltipRadius),
// boxShadow: [boxShadow],
),
child: Builder(
builder: (context) {
final tooltipData =
widget.tooltipBuilder!.call(entry.value);
return RichText(
text: TextSpan(
text: tooltipData.top,
style: AppTextStyle.s16w400Grey2,
children: [
if (tooltipData.midA != null)
TextSpan(
text: "\n${tooltipData.midA}",
style: AppTextStyle.heading2,
),
if (tooltipData.midB != null)
TextSpan(
text: " ${tooltipData.midB}",
style: AppTextStyle.button.copyWith(
color: AppColor.primary1,
height: 4,
),
),
if (tooltipData.bottom != null)
TextSpan(
text: "\n${tooltipData.bottom}",
style: AppTextStyle.legend.copyWith(
color: AppColor.primary,
fontWeight: FontWeight.bold,
),
),
],
),
);
},
),
)
: null,
borderSide:
isTouched ? const BorderSide(color: AppColor.primary) : null,
badgePositionPercentageOffset: 1,
titleStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: const Color(0xffffffff),
),
);
},
).toList();
} |
@2shrestha22 Please provide me a reproducible code (a main.dart file). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
If some value is 0 in
PieChartSectionData
thenpieTouchResponse.touchedSection!.touchedSectionIndex
gives wrong index.To Reproduce
I used official example code and some of SectionData value is 0 in that condition it gives wrong index.
Screenshots
Here is a gif to show the touch response when some value 0 in pie chart.
Versions
fl_chart: ^0.36.1
The text was updated successfully, but these errors were encountered: