S
S
s-zhura2017-09-17 10:02:31
PHP
s-zhura, 2017-09-17 10:02:31

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>

What function to write and how to make cron so that it makes changes to the js file and adds data to the graph at a certain time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Bogachev, 2017-09-17
@sfi0zy

how to make cron make changes to js file

This is a very bad idea, which creates an implicit front-end logic, breaks its assembly, and because of which you can get into a very big mess in the future. If you can’t generate these points in JS at all, then it’s better not to change something in scripts, but to make a separate json file in which the points will be stored and then upload it to the client with Ajax. In this case, you just need to insert the desired line before the last line of this json file ( google->php insert string before last line ), it will be a very simple script, and in order to add it to cron you will need ( google->cron php script ). The answers to both questions are on the first link on stackoverflow. You can read about how you can download to the client here, there is an example and explanations.

Z
Zakharov Alexander, 2017-09-17
@AlexZaharow

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 question

Ask a Question

731 491 924 answers to any question