Skip to content
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

Update LineChartSample6 #1658

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## newVersion
* **Improvement** (by @imaNNeo) Update LineChartSample6 to implement a way to show a tooltip on a single spot, #1620

## 0.67.0
* **FEATURE** (by @julien4215) Add direction property to the [HorizontalLineLabel](https://github.com/imaNNeo/fl_chart/blob/main/repo_files/documentations/base_chart.md#horizontallinelabel) and [VerticalLineLabel](https://github.com/imaNNeo/fl_chart/blob/main/repo_files/documentations/base_chart.md#verticallinelabel), #1574
Expand Down
70 changes: 57 additions & 13 deletions example/lib/presentation/samples/line/line_chart_sample6.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,39 @@ class LineChartSample6 extends StatelessWidget {
aspectRatio: 2,
child: LineChart(
LineChartData(
lineTouchData: const LineTouchData(enabled: false),
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
tooltipRoundedRadius: 0,
getTooltipColor: (spot) => Colors.white,
getTooltipItems: (List<LineBarSpot> touchedSpots) {
return touchedSpots.map((LineBarSpot touchedSpot) {
return LineTooltipItem(
touchedSpot.y.toString(),
TextStyle(
color: touchedSpot.bar.gradient!.colors.first,
fontWeight: FontWeight.bold,
fontSize: 20,
),
);
}).toList();
},
),
getTouchedSpotIndicator: (
_,
indicators,
) {
return indicators
.map((int index) => const TouchedSpotIndicatorData(
FlLine(color: Colors.transparent),
FlDotData(show: false),
))
.toList();
},
touchSpotThreshold: 12,
distanceCalculator:
(Offset touchPoint, Offset spotPixelCoordinates) =>
(touchPoint - spotPixelCoordinates).distance,
),
lineBarsData: [
LineChartBarData(
gradient: LinearGradient(
Expand All @@ -141,12 +173,18 @@ class LineChartSample6 extends StatelessWidget {
),
dotData: FlDotData(
show: true,
getDotPainter: (spot, percent, barData, index) =>
FlDotCirclePainter(
radius: 12,
color: Colors.transparent,
strokeColor: AppColors.mainTextColor2,
),
getDotPainter: (spot, percent, barData, index) {
return FlDotCirclePainter(
radius: 12,
color: Color.lerp(
line1Color1,
line1Color2,
percent / 100,
)!,
strokeColor: Colors.white,
strokeWidth: 1,
);
},
),
),
LineChartBarData(
Expand All @@ -165,12 +203,18 @@ class LineChartSample6 extends StatelessWidget {
),
dotData: FlDotData(
show: true,
getDotPainter: (spot, percent, barData, index) =>
FlDotCirclePainter(
radius: 12,
color: Colors.transparent,
strokeColor: AppColors.mainTextColor2,
),
getDotPainter: (spot, percent, barData, index) {
return FlDotCirclePainter(
radius: 12,
color: Color.lerp(
line2Color1,
line2Color2,
percent / 100,
)!,
strokeColor: Colors.white,
strokeWidth: 1,
);
},
),
),
],
Expand Down