Code Monkey home page Code Monkey logo

Comments (1)

PreethikaSelvam avatar PreethikaSelvam commented on June 26, 2024

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

from flutter-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.