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

y-axis title above the chart and custom content display #1675

Closed
happylh2012 opened this issue Feb 18, 2024 · 2 comments
Closed

y-axis title above the chart and custom content display #1675

happylh2012 opened this issue Feb 18, 2024 · 2 comments
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.

Comments

@happylh2012
Copy link

1:Can the content of the y-axis on the chart be placed above the chart ? This is because the width of the display on mobile phones is limited, and expanding the display area of the chart could be helpful.
2:Is it possible to expand custom content, such as displaying weather icons at fixed intervals above the chart?

@VijayakumarMariappan VijayakumarMariappan added charts Charts component open Open labels Feb 21, 2024
@PreethikaSelvam
Copy link
Contributor

Hi,

Query 1: Need to place the y-axis above the chart.

We would like to let you know, we cannot position both the x-axis and y-axis horizontally. To transpose the axis, you can use the transposed property to switch the horizontal and vertical axes. However, we cannot position both the x-axis and y-axis horizontally. If you want to move axis within the plot area and expand the series rendering area, we suggest moving the axis tick position and axis label position inside by using the tickPosition and labelPosition respectively.

Query 2: Need to add custom content (weather icons) above the chart.

We have implemented a logic to enable users to toggle between hourly and daily data representations on a chart. This functionality is facilitated by a boolean variable, _showHourlyData, which determines the type of data to display. When the user interacts with the provided buttons, this variable is updated accordingly, triggering a re-render of the chart with the selected interval. If hourly data is chosen, the function iterates through each hour within a specified week, while for daily data, it iterates through each day. DateTimeAxis adjusted to display appropriate time intervals based on the user's selection by using the interval and intervalType properties. We have shared a code snippet and a sample for your reference below. You can modify the sample based on your needs.

Code snippet:

`
bool _showHourlyData = true;

List generateChartData(
bool showHourlyData, int week, DateTime currentDate, int hours) {
List data = [];
Random random = Random();

if (showHourlyData) {
// Generate hourly data for a week
for (int i = 0; i <= week * hours; i++) {
double y = random.nextDouble() *
100; // Generate a random y-value between 0 and 100
data.add(ChartData(currentDate.add(Duration(hours: i)), y));
}
} else {
// Generate daily data for a week
for (int i = 0; i < week; i++) {
double y = random.nextDouble() *
100; // Generate a random y-value between 0 and 100
data.add(ChartData(currentDate.add(Duration(days: i)), y));
}
}

return data;
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton.icon(
onPressed: () {
setState(() {
_showHourlyData = true;
});
},
icon: const Icon(Icons.wb_sunny),
label: const Text('Show By Hour'),
),
const SizedBox(width: 10),
ElevatedButton.icon(
onPressed: () {
setState(() {
_showHourlyData = false;
});
},
icon: const Icon(Icons.cloud),
label: const Text('Show By Day'),
),
],
),
Expanded(
child: Center(
child: SfCartesianChart(
primaryXAxis: DateTimeAxis(
minimum: DateTime(2022, 1, 1),
maximum: DateTime(2022, 1, 7),
majorGridLines: const MajorGridLines(width: 0),
minorGridLines: const MinorGridLines(width: 0),
interval: _showHourlyData ? 3 : 1,
intervalType: _showHourlyData
? DateTimeIntervalType.hours
: DateTimeIntervalType.days,
),
primaryYAxis: const NumericAxis(
majorGridLines: MajorGridLines(width: 0),
minorGridLines: MinorGridLines(width: 0),
),
series: [
AreaSeries<ChartData, DateTime>(
animationDuration: 0,
dataSource: generateChartData(
_showHourlyData, 7, DateTime(2022, 1, 1), 24),
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
)
],
),

`
Please let us know if you need any further assistance.

Regards,
Preethika Selvam.
bd557706.zip

@LavanyaGowtham2021 LavanyaGowtham2021 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Feb 22, 2024
@LavanyaGowtham2021
Copy link
Collaborator

LavanyaGowtham2021 commented Mar 21, 2024

Please reopen this ticket, if you need any further assistance on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
charts Charts component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

4 participants