i want to build a syncfusion chart in flutter. i retrive data from firebase realtime database. the data would be show in the chart. and i got a problem here. they say about 'millisecondsSinceEpoch'. but i don't have it in my code. but there's got a problem. this is my code :
import 'dart:async';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class Chart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: HolyChart(),
),
);
}
}
class HolyChart extends StatefulWidget {
@override
_HolyChartState createState() => _HolyChartState();
}
class _HolyChartState extends State<HolyChart> {
Timer _timer;
int _count = 0;
ChartSeriesController _seriesController;
final _dbReference = FirebaseDatabase.instance.reference();
List _chartData = <ChartData>[];
int _values;
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
_updateData(Timer timer) {
_chartData.add(ChartData(_count, _values));
if (_chartData.length == 20) {
_chartData.removeAt(0);
_seriesController.updateDataSource(
addedDataIndexes: <int>[_chartData.length - 1],
removedDataIndexes: <int>[0]);
}
_count = _count + 1;
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: _dbReference.child("Data").onValue,
builder: (context, snapshot) {
Widget widget;
if (snapshot.hasData &&
!snapshot.hasError &&
snapshot.data.snapshot.value != null) {
_values = snapshot.data.snapshot.value["Moisture"];
if (_values != null) {
_timer = Timer.periodic(Duration(seconds: 3), _updateData(_timer));
}
widget = Container(
child: SfCartesianChart(
tooltipBehavior: TooltipBehavior(enable: true),
primaryXAxis: DateTimeAxis(),
series: <LineSeries<ChartData, int>>[
LineSeries<ChartData, int>(
dataSource: _chartData,
xValueMapper: (ChartData data, _) => data.xAxisValue,
yValueMapper: (ChartData data, _) => data.yAxisValue,
)
],
),
);
} else {
widget = Center(child: CircularProgressIndicator());
}
return widget;
},
);
}
}
class ChartData {
ChartData(this.xAxisValue, this.yAxisValue);
ChartData.fromMap(this.xAxisValue, this.yAxisValue);
final int xAxisValue;
final int yAxisValue;
}
and this is the problem for my code. what's mean with the function 'millisecondsSinceEpoch'? b
The following NoSuchMethodError was thrown building LayoutBuilder:
Class 'int' has no instance getter 'millisecondsSinceEpoch'.
Receiver: 0
Tried calling: millisecondsSinceEpoch
can anyone help me?? thank you so much for your help...
My guess is that you use
primaryXAxis: DateTimeAxis(),
but none of your x/y value is a Date. TheSfCartesianChart
tries to convert x or y as a date (millisecondsSinceEpoch
is relative to the usage of a date) but both of them are int.Have a look at this (search for
DateTimeAxis
, there is different examples) : https://help.syncfusion.com/flutter/cartesian-charts/axis-customization