Flutter - Iterate chart with json
up vote
0
down vote
favorite
I'm trying to show a chart with a api json data. I made some a iteration and save result on a global variable, then i put this variable in chart, but variable return null, does not have any data. If i print list in foreach has data but if I print in widget is null. I read this but code looks very different so i can´t follow.
Variables
List<charts.Series<TimeSeriesSales, DateTime>> seriesList;
List<TimeSeriesSales> data = ;
Get data
final String url = 'URL';
class TimeSeriesSales {
final DateTime fecha;
final double valor;
TimeSeriesSales(this.fecha, this.valor);
}
Future<Null> getUserDetails() async {
final response = await http.get(
url,
headers: {
HttpHeaders.authorizationHeader:
"HEADER "
},
);
final responseJson = json.decode(response.body);
setState(() {
for (Map user in responseJson) {
var fecha= new DateTime.fromMillisecondsSinceEpoch(user['fecha']).toLocal();
data.add(TimeSeriesSales(new DateTime(fecha.year, fecha.month,fecha.day), user['valor']));
print (data.toString());
}
});
}
Init State
void initState() {
super.initState();
getUserDetails();
seriesList = _createSampleData();
animate = false;
}
Fill TimeSeries
List<charts.Series<TimeSeriesSales, DateTime>> _createSampleData() {
return [
new charts.Series<TimeSeriesSales, DateTime>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimeSeriesSales valor, _) => valor.fecha,
measureFn: (TimeSeriesSales valor, _) => valor.valor,
data: data,
)
];
}
}
Widget
Widget build(BuildContext context) {
return new Scaffold(
new Expanded(
child: new charts.TimeSeriesChart(
seriesList,
animate: animate,
defaultRenderer: new charts.BarRendererConfig<DateTime>(),
domainAxis: new charts.DateTimeAxisSpec(usingBarRenderer: true),
defaultInteractions: false,
behaviors: [
new charts.SelectNearest(),
new charts.DomainHighlighter()
],
),
),
)
Anybody knows why list does not have data in widget? And somebody know what is the right way to iterate chart on init?
charts dart flutter
add a comment |
up vote
0
down vote
favorite
I'm trying to show a chart with a api json data. I made some a iteration and save result on a global variable, then i put this variable in chart, but variable return null, does not have any data. If i print list in foreach has data but if I print in widget is null. I read this but code looks very different so i can´t follow.
Variables
List<charts.Series<TimeSeriesSales, DateTime>> seriesList;
List<TimeSeriesSales> data = ;
Get data
final String url = 'URL';
class TimeSeriesSales {
final DateTime fecha;
final double valor;
TimeSeriesSales(this.fecha, this.valor);
}
Future<Null> getUserDetails() async {
final response = await http.get(
url,
headers: {
HttpHeaders.authorizationHeader:
"HEADER "
},
);
final responseJson = json.decode(response.body);
setState(() {
for (Map user in responseJson) {
var fecha= new DateTime.fromMillisecondsSinceEpoch(user['fecha']).toLocal();
data.add(TimeSeriesSales(new DateTime(fecha.year, fecha.month,fecha.day), user['valor']));
print (data.toString());
}
});
}
Init State
void initState() {
super.initState();
getUserDetails();
seriesList = _createSampleData();
animate = false;
}
Fill TimeSeries
List<charts.Series<TimeSeriesSales, DateTime>> _createSampleData() {
return [
new charts.Series<TimeSeriesSales, DateTime>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimeSeriesSales valor, _) => valor.fecha,
measureFn: (TimeSeriesSales valor, _) => valor.valor,
data: data,
)
];
}
}
Widget
Widget build(BuildContext context) {
return new Scaffold(
new Expanded(
child: new charts.TimeSeriesChart(
seriesList,
animate: animate,
defaultRenderer: new charts.BarRendererConfig<DateTime>(),
domainAxis: new charts.DateTimeAxisSpec(usingBarRenderer: true),
defaultInteractions: false,
behaviors: [
new charts.SelectNearest(),
new charts.DomainHighlighter()
],
),
),
)
Anybody knows why list does not have data in widget? And somebody know what is the right way to iterate chart on init?
charts dart flutter
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to show a chart with a api json data. I made some a iteration and save result on a global variable, then i put this variable in chart, but variable return null, does not have any data. If i print list in foreach has data but if I print in widget is null. I read this but code looks very different so i can´t follow.
Variables
List<charts.Series<TimeSeriesSales, DateTime>> seriesList;
List<TimeSeriesSales> data = ;
Get data
final String url = 'URL';
class TimeSeriesSales {
final DateTime fecha;
final double valor;
TimeSeriesSales(this.fecha, this.valor);
}
Future<Null> getUserDetails() async {
final response = await http.get(
url,
headers: {
HttpHeaders.authorizationHeader:
"HEADER "
},
);
final responseJson = json.decode(response.body);
setState(() {
for (Map user in responseJson) {
var fecha= new DateTime.fromMillisecondsSinceEpoch(user['fecha']).toLocal();
data.add(TimeSeriesSales(new DateTime(fecha.year, fecha.month,fecha.day), user['valor']));
print (data.toString());
}
});
}
Init State
void initState() {
super.initState();
getUserDetails();
seriesList = _createSampleData();
animate = false;
}
Fill TimeSeries
List<charts.Series<TimeSeriesSales, DateTime>> _createSampleData() {
return [
new charts.Series<TimeSeriesSales, DateTime>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimeSeriesSales valor, _) => valor.fecha,
measureFn: (TimeSeriesSales valor, _) => valor.valor,
data: data,
)
];
}
}
Widget
Widget build(BuildContext context) {
return new Scaffold(
new Expanded(
child: new charts.TimeSeriesChart(
seriesList,
animate: animate,
defaultRenderer: new charts.BarRendererConfig<DateTime>(),
domainAxis: new charts.DateTimeAxisSpec(usingBarRenderer: true),
defaultInteractions: false,
behaviors: [
new charts.SelectNearest(),
new charts.DomainHighlighter()
],
),
),
)
Anybody knows why list does not have data in widget? And somebody know what is the right way to iterate chart on init?
charts dart flutter
I'm trying to show a chart with a api json data. I made some a iteration and save result on a global variable, then i put this variable in chart, but variable return null, does not have any data. If i print list in foreach has data but if I print in widget is null. I read this but code looks very different so i can´t follow.
Variables
List<charts.Series<TimeSeriesSales, DateTime>> seriesList;
List<TimeSeriesSales> data = ;
Get data
final String url = 'URL';
class TimeSeriesSales {
final DateTime fecha;
final double valor;
TimeSeriesSales(this.fecha, this.valor);
}
Future<Null> getUserDetails() async {
final response = await http.get(
url,
headers: {
HttpHeaders.authorizationHeader:
"HEADER "
},
);
final responseJson = json.decode(response.body);
setState(() {
for (Map user in responseJson) {
var fecha= new DateTime.fromMillisecondsSinceEpoch(user['fecha']).toLocal();
data.add(TimeSeriesSales(new DateTime(fecha.year, fecha.month,fecha.day), user['valor']));
print (data.toString());
}
});
}
Init State
void initState() {
super.initState();
getUserDetails();
seriesList = _createSampleData();
animate = false;
}
Fill TimeSeries
List<charts.Series<TimeSeriesSales, DateTime>> _createSampleData() {
return [
new charts.Series<TimeSeriesSales, DateTime>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimeSeriesSales valor, _) => valor.fecha,
measureFn: (TimeSeriesSales valor, _) => valor.valor,
data: data,
)
];
}
}
Widget
Widget build(BuildContext context) {
return new Scaffold(
new Expanded(
child: new charts.TimeSeriesChart(
seriesList,
animate: animate,
defaultRenderer: new charts.BarRendererConfig<DateTime>(),
domainAxis: new charts.DateTimeAxisSpec(usingBarRenderer: true),
defaultInteractions: false,
behaviors: [
new charts.SelectNearest(),
new charts.DomainHighlighter()
],
),
),
)
Anybody knows why list does not have data in widget? And somebody know what is the right way to iterate chart on init?
charts dart flutter
charts dart flutter
asked 2 days ago
El Hombre Sin Nombre
153114
153114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You aren't re-creating the series after you've fetched and parsed the data. Call seriesList = _createSampleData();
again after iterating the responseData
, inside the setState
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You aren't re-creating the series after you've fetched and parsed the data. Call seriesList = _createSampleData();
again after iterating the responseData
, inside the setState
.
add a comment |
up vote
0
down vote
accepted
You aren't re-creating the series after you've fetched and parsed the data. Call seriesList = _createSampleData();
again after iterating the responseData
, inside the setState
.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You aren't re-creating the series after you've fetched and parsed the data. Call seriesList = _createSampleData();
again after iterating the responseData
, inside the setState
.
You aren't re-creating the series after you've fetched and parsed the data. Call seriesList = _createSampleData();
again after iterating the responseData
, inside the setState
.
answered yesterday
Richard Heap
4,6142212
4,6142212
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373149%2fflutter-iterate-chart-with-json%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown