fl_chart
fl_chart copied to clipboard
added custom properties attribute to line chart bar data
Hi, thanks for providing this awesome library.
In this PR, I added a properties
attribute as Map<string, dynamic>
in order to store optional line curve parameters, like name or any other curve setting. by this change if you have multiple curves in a chart, now it's possible to show the name of each curve next to the value on the tooltip message.
@imaNNeo, is there any issue with this PR? please let me know, thanks.
Yes, there are issues with this PR,
- I think it is better to use dynamic or Object type for the properties
- I think you can wrap the
LineChartBarData
to add your own custom data, you can check out this message - Please read the contributing guidelines, (you should not change the library version)
Thanks for your reply :) Here is my comments:
-
I defined the type of
properties
attribute, because if we want to include that attribute inlerp
operation, the type must be known. so we can't use thedynamic
orObject
type. -
I think it would be the best if you include this hint in
readme
file (since currently there are multiple PR requests for this types of features). I tried to do that and it worked. Just need to override thecopyWith
operation. I added here as a reference:
class LineChartBarDataWrapper extends LineChartBarData {
final String label;
LineChartBarDataWrapper({
super.spots,
super.show,
super.color,
super.gradient,
super.barWidth,
super.isCurved,
super.curveSmoothness,
super.preventCurveOverShooting,
super.preventCurveOvershootingThreshold,
super.isStrokeCapRound,
super.isStrokeJoinRound,
super.belowBarData,
super.aboveBarData,
super.dotData,
super.showingIndicators,
super.dashArray,
super.shadow,
super.isStepLineChart,
super.lineChartStepData,
required this.label,
});
@override
LineChartBarDataWrapper copyWith({
List<FlSpot>? spots,
bool? show,
Color? color,
Gradient? gradient,
double? barWidth,
bool? isCurved,
double? curveSmoothness,
bool? preventCurveOverShooting,
double? preventCurveOvershootingThreshold,
bool? isStrokeCapRound,
bool? isStrokeJoinRound,
BarAreaData? belowBarData,
BarAreaData? aboveBarData,
FlDotData? dotData,
List<int>? dashArray,
List<int>? showingIndicators,
Shadow? shadow,
bool? isStepLineChart,
LineChartStepData? lineChartStepData,
String? label,
}) {
return LineChartBarDataWrapper(
spots: spots ?? this.spots,
show: show ?? this.show,
color: color ?? this.color,
gradient: gradient ?? this.gradient,
barWidth: barWidth ?? this.barWidth,
isCurved: isCurved ?? this.isCurved,
curveSmoothness: curveSmoothness ?? this.curveSmoothness,
preventCurveOverShooting:
preventCurveOverShooting ?? this.preventCurveOverShooting,
preventCurveOvershootingThreshold: preventCurveOvershootingThreshold ??
this.preventCurveOvershootingThreshold,
isStrokeCapRound: isStrokeCapRound ?? this.isStrokeCapRound,
isStrokeJoinRound: isStrokeJoinRound ?? this.isStrokeJoinRound,
belowBarData: belowBarData ?? this.belowBarData,
aboveBarData: aboveBarData ?? this.aboveBarData,
dotData: dotData ?? this.dotData,
dashArray: dashArray ?? this.dashArray,
showingIndicators: showingIndicators ?? this.showingIndicators,
shadow: shadow ?? this.shadow,
isStepLineChart: isStepLineChart ?? this.isStepLineChart,
lineChartStepData: lineChartStepData ?? this.lineChartStepData,
label: label ?? this.label,
);
}
}