Hi there! Trying to plot two daily profit data points ('day" and "total") using line echarts. Everything is prepped, just stuck on the task of setting up and saving the array every 24 hours. Here is the function generating the data:
let time = new Date(new Date().getTime())
msgMessage.payload = {'day':paper_dc, 'total':paper_ch, 'time': time}
output:
{"day":"0.38","total":"1.75","time":"2022-11-27T19:42:22.657Z"}
and here is the echart template:
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script>
<body>
<!-- prepare a DOM container with width and height -->
<div id="divProfit" style="padding: 0px; margin:-20px 0px 0px -90px; width:1330px; height:290px;"></div>
<script type="text/javascript">
var dom = document.getElementById("divProfit");
var myChart =null
myChart = echarts.init(dom);
option = null;
let day = [["2018-08-16T10:04:01.339Z",1],[ "2018-08-17T10:14:13.914Z",-1],[ "2018-08-18T10:40:03.147Z",2.5],[ "2018-08-19T11:50:14.335Z",1.5]]
option = {
xAxis : [
{
type: 'time',
boundaryGap:false,
axisLabel: {
formatter: (function(value){
return moment(value).format('M/D');
})
}
}
],
yAxis : [
{
type : 'value',
splitLine: {lineStyle: {color:'#434651'}},
}
],
dataZoom: [
{
type: 'slider',
backgroundColor: "rgba(0, 0, 0, 0.05)",
fillerColor: "rgba(0, 0, 0, 0.15)",
moveHandleStyle: {
color: "rgba(0, 0, 0, 0)"
},
start: 0,
end: 100
}
],
series : [
{
name:'Total',
type:'line',
smooth: true,
lineStyle: {
normal: {color: '#079F70', opacity: 0.3}
},
areaStyle: {color: '#079F70', opacity: 0.3},
data: [["2018-08-16T10:04:01.339Z",2],[ "2018-08-17T10:14:13.914Z",2.5],[ "2018-08-18T10:40:03.147Z",3],[ "2018-08-19T11:50:14.335Z",3.5]]
},
{
name:'Day',
type:'line',
smooth: true,
lineStyle: {
normal: {color:'#079F70', opacity: 0.9}
},
areaStyle: {color: '#079F70', opacity: 0.9},
// data: [["2018-08-16T10:04:01.339Z",1],[ "2018-08-17T10:14:13.914Z",-1],[ "2018-08-18T10:40:03.147Z",2.5],[ "2018-08-19T11:50:14.335Z",1.5]]
data: day
}
]
};
if (option && typeof option === "object")
{
myChart.setOption(option, true);
}
</script>
</body>
The day/total values are continuously updated but at midnight the data point marking the end of day is saved (I assume local file), so the chart is showing two types of data (saved history and current day).
Also, doing something wrong when I try to assign data in the chart template to variable - i.e :
let day = [["2018-08-16T10:04:01.339Z",1],[ "2018-08-17T10:14:13.914Z",-1],[ "2018-08-18T10:40:03.147Z",2.5],[ "2018-08-19T11:50:14.335Z",1.5]]'
is giving an error. Thanks for your help!!