Repository navigation
Description
- flutter version any
- syncfusion_flutter_charts : ^18.3.44
1. It's normal to run the app the first time

**2.when refresh the widget or perform hot reload , it will display errors(end to end),The data is obtained by network request **

code
`class EchartsWidget extends StatefulWidget{
@OverRide
State createState() {
return EchartsWidgetState();
}
}
class EchartsWidgetState extends State{
RefreshController _refreshController =
RefreshController(initialRefresh: false);
void _onRefresh() async {
// monitor network fetch
await Future.delayed(Duration(milliseconds: 1000));
if (mounted)
setState(() {
});
// if failed,use refreshFailed()
_refreshController.refreshCompleted();
}
List resultDataList = [];
List todayDataListOld = [];
List yesterdayDataListOld = [];
var unit;
List todayDataList = List();
List yesterdayDataList = List();
timestampToDateechart(timestamp) {
var date = DateTime.fromMillisecondsSinceEpoch(timestamp);
return date.toString().substring(0, 16);
}
getEchartData(List resultDataList) {
ResultData data1 = resultDataList[0];
ResultData data2 = resultDataList[1];
if (data1.name == "今日") {
todayDataListOld = data1.data;
yesterdayDataListOld = data2.data;
} else {
todayDataListOld = data2.data;
yesterdayDataListOld = data1.data;
}
for (int i = 0; i < todayDataListOld.length; i++) {
String timestamp = timestampToDateechart(todayDataListOld[i].date-(24 * 60 * 60 * 1000));
print("今日" + timestamp);
var time = DateTime.parse(timestamp);
var value = double.parse(todayDataListOld[i].value);
todayDataList.add(new EchartsData(time, value));
}
for (int i = 0; i < yesterdayDataListOld.length; i++) {
String timestamp = timestampToDateechart(yesterdayDataListOld[i].date);
var time = DateTime.parse(timestamp);
print("昨日" + timestamp);
var value = double.parse(yesterdayDataListOld[i].value) ;
yesterdayDataList.add(new EchartsData(time, value));
}
}
@OverRide
Widget build(BuildContext context) {
return SmartRefresher(
enablePullDown: true,
header: MaterialClassicHeader(),
controller: _refreshController,
onRefresh: _onRefresh,
child: Container(
child: FutureBuilder(
future: WholeFactoryService().getEchartsData(),
builder: (BuildContext context, AsyncSnapshot snapshot){
if(snapshot.connectionState == ConnectionState.done){
resultDataList = snapshot.data;
getEchartData(resultDataList);
return Container(
width: 300,
height: 300,
child: SfCartesianChart(
title: ChartTitle(
text: '发电负荷(MW)',
alignment: ChartAlignment.near
),
legend: Legend(
isVisible:true,
position: LegendPosition.auto,
),
backgroundColor: Color(0xff2775c7),
// Initialize category axis
primaryXAxis: DateTimeAxis(
//isVisible: true,
dateFormat: DateFormat.Hm(),
),
primaryYAxis: NumericAxis(
axisLine: AxisLine(width: 0),
),
series: <LineSeries<EchartsData, DateTime>>[
LineSeries<EchartsData, DateTime>(
color: Color(0xff05fcff),
// Bind data source
dataSource: todayDataList,
xValueMapper: (EchartsData data, _) => data.time,
yValueMapper: (EchartsData data, _) => data.value,
legendItemText: "今日",
),
LineSeries<EchartsData, DateTime>(
color: Color(0xfff5a92f),
// Bind data source
dataSource: yesterdayDataList,
xValueMapper: (EchartsData data, _) => data.time,
yValueMapper: (EchartsData data, _) => data.value,
legendItemText: "昨日",
isVisible: true,
),
]
),
);
}else{
return Container();
}
},
),
),
);
}
}
class EchartsData {
EchartsData(this.time, this.value);
DateTime time;
num value;
}`
Activity
SriramKiranSenthilkumar commentedon Nov 3, 2020
Hi @baliejun,
Greetings from Syncfusion. We have analyzed your scenario with the provided information and we tried to replicate the reported issue at our end regarding the chart displays errors (end to end) when hot-reloading or refreshing the widget. Unfortunately, we are not able to replicate the reported issue at our end. We also found that in the provided screenshot, you have told that the chart renders a line from end to start of the chart when hot-reloading. So we suspect that the data source which you are passing into the chart on hot-reload or refreshing the widget is the cause for the issue. So, we kindly request you to share the data source values which you are passing to the chart from the network request when hot-reloading or refreshing the widget or you can print the data source values in the console when hot-reloading or refreshing the widget and share us the console log for checking whether the data source values are passed correctly into the chart and also if possible, kindly share us a simple sample that can replicate the reported issue so that it will be helpful in providing the solutions sooner.
Regards,
Sriram Kiran
baliejun commentedon Nov 4, 2020
Hi,SriramKiranSenthilkumar ,
Thanks for your quick response,I've found that the issue is caused by data.
baliejun commentedon Nov 4, 2020
Hi,SriramKiranSenthilkumar ,
There is another question, How to achieve this effect(One of them is shaded)?

SriramKiranSenthilkumar commentedon Nov 4, 2020
Hi @baliejun,
We have analyzed your query at our end and we have created a simple chart sample in which we have rendered two chart series (area series and line series) and we have used the
gradientproperty of theAreaSeriesin order to add shaded colours for the chart region and with the help of theborderColor,borderWidthandborderDrawModeproperties of the Area series, we have set the border colour and width for the area series and we have set the value of theborderDrawModeproperty toBorderDrawMode.topso that the border for the area series will get rendered only in the top. Please refer the code snippet below for further reference.Screenshot:

The sample for reference can be found below.
sample.zip
Please check with the above-attached sample and revert us if have further concerns.
For further reference on the gradient support and border customization in area series, please check the user guides below.
Regards,
Sriram Kiran
baliejun commentedon Nov 5, 2020
Hi,Sriram Kiran ,
Thank you very much.
Regards,
Liejun.