From dc7428e8337d158ef14b85ca93f17cf4ef53f87e Mon Sep 17 00:00:00 2001 From: Pavithra Nandhini Ramachandran Date: Wed, 24 Feb 2021 10:36:47 +0530 Subject: [PATCH] committed --- lib/main.dart | 95 +++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 74097a8..891a336 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,9 +11,7 @@ class ChartApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Chart Demo', - theme: ThemeData( - primarySwatch: Colors.blue - ), + theme: ThemeData(primarySwatch: Colors.blue), home: MyHomePage(), ); } @@ -28,6 +26,14 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { + TooltipBehavior _tooltipBehavior; + + @override + void initState() { + _tooltipBehavior = TooltipBehavior(enable: true); + super.initState(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -39,53 +45,52 @@ class _MyHomePageState extends State { height: 500, width: 320, child: SfCartesianChart( - backgroundColor: Colors.white, - plotAreaBackgroundColor: Colors.white, - onTooltipRender: (TooltipArgs args) { - if (args.pointIndex == 0) { - //Tooltip without header - args.header = ''; - } - if (args.pointIndex == 1) { - //Tooltip with customized header - args.header = 'Sold'; - } - if (args.pointIndex == 2) { - //Tooltip with X and Y positions of data points - args.header = 'x : y'; - args.text = '${args.locationX.floor()} : ${args.locationY.floor()}'; - } - if(args.pointIndex == 3) { - //Tooltip with formatted DateTime values - List> chartdata = args.dataPoints; - args.header = DateFormat('d MMM yyyy').format(chartdata[3].x); - args.text = '${chartdata[3].y}'; - } - }, + backgroundColor: Colors.white, + plotAreaBackgroundColor: Colors.white, + onTooltipRender: (TooltipArgs args) { + if (args.pointIndex == 0) { + //Tooltip without header + args.header = ''; + } + if (args.pointIndex == 1) { + //Tooltip with customized header + args.header = 'Sold'; + } + if (args.pointIndex == 2) { + //Tooltip with X and Y positions of data points + args.header = 'x : y'; + args.text = + '${args.locationX.floor()} : ${args.locationY.floor()}'; + } + if (args.pointIndex == 3) { + //Tooltip with formatted DateTime values + List> chartdata = + args.dataPoints; + args.header = + DateFormat('d MMM yyyy').format(chartdata[3].x); + args.text = '${chartdata[3].y}'; + } + }, primaryXAxis: DateTimeAxis( - interval: 30, - intervalType: DateTimeIntervalType.days - ), + interval: 30, intervalType: DateTimeIntervalType.days), // Enable tooltip - tooltipBehavior: TooltipBehavior(enable: true), + tooltipBehavior: _tooltipBehavior, series: >[ LineSeries( - enableTooltip: true, - dataSource: [ - SalesData(DateTime(2020, 01, 31), 35), - SalesData(DateTime(2020, 02, 28), 28), - SalesData(DateTime(2020, 03, 31), 34), - SalesData(DateTime(2020, 04, 30), 32), - SalesData(DateTime(2020, 05, 31), 40) - ], - xValueMapper: (SalesData sales, _) => sales.date, - yValueMapper: (SalesData sales, _) => sales.sales, + enableTooltip: true, + dataSource: [ + SalesData(DateTime(2020, 01, 31), 35), + SalesData(DateTime(2020, 02, 28), 28), + SalesData(DateTime(2020, 03, 31), 34), + SalesData(DateTime(2020, 04, 30), 32), + SalesData(DateTime(2020, 05, 31), 40) + ], + xValueMapper: (SalesData sales, _) => sales.date, + yValueMapper: (SalesData sales, _) => sales.sales, ) - ] - ), + ]), ), - ) - ); + )); } } @@ -94,4 +99,4 @@ class SalesData { final DateTime date; final double sales; -} \ No newline at end of file +}