-
Notifications
You must be signed in to change notification settings - Fork 782
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
Question / Need help #2136
Comments
Can I please get a response :/? |
Hello :/, it's been 3 weeks |
Hi @Welnnys, We have analyzed you query and you can achieve your requirement by using LegendItemBuilder. However by reversing the text alone in legend does not reflect in chart segment when click on respective legend item. We have shared code snippet and sample for your reference. Code Snippet: @override
Widget build(BuildContext context) {
// Reverse the chart data only for the legend
List<_ChartData> reversedChartData = List.from(chartData.reversed);
return Scaffold(
body: SfCircularChart(
……………….
// Customizing the legend to show in reversed order
legendItemBuilder: (String name, dynamic series, dynamic point, int index) {
final ChartPoint _point = point as ChartPoint;
// Define colors for each category in reversed order
final Color color = index == 0
? Colors.blue
: index == 1
? Colors.green
: Colors.red;
return Container(
padding: const EdgeInsets.all(4),
child: Row(
children: [
// Circular shape icon with custom color
Container(
width: 10,
height: 10,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color,
),
),
const SizedBox(width: 8),
// Display the reversed label
Text(reversedChartData[index].x),
],
),
);
},
…………….
For more information, kindly refer to the following UG, Sample : gh_2136.zip Regards, |
And there is no way to make it reflect the chart? |
and to have the default legend icons aswell |
I have already responded, I am waiting for you to respond |
Is there a way to reverse the order of the labels on the right side without reversing the order of the circles and if possible to also keep the default legend icons (those little clickable circles)?
// overview_model.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:intl/intl.dart';
class OverviewModel {
final String userUID;
OverviewModel(this.userUID);
Future<List> fetchActivityCounts() async {
final now = DateTime.now();
final currentMonthYear = DateFormat('MM-yyyy').format(now);
}
Future<List> fetchTotalActivityTime() async {
final now = DateTime.now();
final currentMonthYear = DateFormat('MM-yyyy').format(now);
}
Future<List<Map<String, dynamic>>> fetchPersonalBestActivities(
List sortedActivityTypes) async {
List allActivityTypes = [
'Running',
'Cycling',
'Walking',
'Swimming',
'Volleyball',
'Bouldering',
'Football',
'Basketball',
'Fitness',
];
}
List generateExampleChartData() {
List exampleData = [
ChartData('Example 1', 3, 'No Data'),
ChartData('Example 2', 5, 'No Data'),
ChartData('Example 3', 10, 'No Data'),
ChartData('Example 4', 15, 'No Data'),
ChartData('Example 5', 20, 'No Data'),
];
}
}
class ChartData {
ChartData(this.category, this.value, this.formattedTime);
final String category;
final double value;
final String formattedTime;
}
// overview_page.dart
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:sporti_angel_kolev/models/overview_model.dart';
import 'package:sporti_angel_kolev/controllers/overview_controller.dart';
import 'package:sporti_angel_kolev/common/activity_list_widget.dart';
import 'package:sporti_angel_kolev/common/profile_picture.dart';
import 'package:sporti_angel_kolev/common/user_information.dart';
class OverviewPage extends StatefulWidget {
const OverviewPage({super.key});
@OverRide
_OverviewPageState createState() => _OverviewPageState();
}
class _OverviewPageState extends State {
bool showTotalActivityTime = true;
late OverviewController _controller;
@OverRide
void initState() {
super.initState();
final userUID = UserInformation().userUID;
_controller = OverviewController(OverviewModel(userUID));
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
surfaceTintColor: Colors.white,
title: const Text(
'Overview',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
centerTitle: true,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
actions: const [ProfilePicture()],
),
body: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: () {
setState(() {
showTotalActivityTime = !showTotalActivityTime;
});
},
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(
vertical: 15.0, horizontal: 30.0),
backgroundColor: Colors.redAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
elevation: 5,
shadowColor: Colors.black,
),
child: Text(
showTotalActivityTime
? 'Monthly Activity Count'
: 'Monthly Total Activity Time',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
Expanded(
child: Column(
children: [
Flexible(
child: FutureBuilder<List>(
future: showTotalActivityTime
? _controller.fetchTotalActivityTime()
: _controller.fetchActivityCounts(),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(
Colors.red)));
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
final chartData = snapshot.data ?? [];
}
}
The text was updated successfully, but these errors were encountered: