Answer the question
In order to leave comments, you need to log in
How to schedule daily changes to a js file (graph)?
There is a div in which the figure is updated every day. Let's say today it's 185:
<div id="summresult">185</div>
Есть файл js (график), в который каждый день нужно добавлять данные, в зависимости от значения <div id="summresult">...</div>
window. onload = function () {
var chart= new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
zoomEnabled:true,
legend:{
verticalAlign: "bottom",
horizontalAlign: "center"
},
axisY:{
includeZero: false,
prefix: "$",
gridColor: "#DDD",
gridThickness: 1,
gridDashType: "dot",
tickThickness: 1,
interval: 250,
maximum: 1900
},
axisX:{
valueFormatString: "DD-MM-YY",
gridColor: "#DDD",
gridDashType: "dot",
tickThickness: 1,
gridThickness: 1
},
toolTip: {
borderColor: "#337ba7",
backgroundColor: "#fbfbfb",
borderThickness: 2,
cornerRadius: 3,
fontStyle: "normal",
fontFamily: "tahoma"
},
data: [
{
type: "spline",
markerSize: 8,
markerColor: "#337ba7",
markerBorderColor: "#FFF",
markerBorderThickness: 1,
lineColor: "#337ba7",
toolTipContent: "{x} <strong>${y} <strong>",
dataPoints: [
{ x: new Date(2017,07,15), y: 215.00 }
,{ x: new Date(2017,07,16), y: 409.00 }
,{ x: new Date(2017,07,17), y: 185.00 }
]
}
]
});
chart.render();
}
Строчка, которая должна была добавиться: ,{ x: new Date(2017,07,17), y: 185.00 }
Соответственно, на следующий день должна добавиться строчка с цифрой из <div id="summresult">...</div>
Answer the question
In order to leave comments, you need to log in
how to make cron make changes to js file
If you need a cron exactly in a file (all sorts of circumstances happen), then I would advise you to have a separate file for this in a simple text form, which stores only the data that cron adds one line at a time. Then the client reads the page and reads this file separately, parses it and builds a graph. And in the way you do it, as Ivan Bogachev said, it 's a bad idea. For example, you can break the syntax of the source file and then the user will not see anything at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question