How to process csv data (datetime) month, week, day, hour in highstock highcharts












0














I have a CSV file with following format:



<pre id="csv" style="display:none">
DATES,WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER
01/10/2018 00:00,25,16,13,1,0
01/10/2018 01:00,24,5,9,3,2
01/10/2018 02:00,28,6,17,0,6


The data range is 01/10/2018 00:00 - 31/10/2018 00:00
Interval is every hour.
I am using highstock stacked column with 5 categories: WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER.
My problem is, that the highstock navigator displays the data incorrectly. I think I have to customise property in range selector or navigator, but I can't find any documentation online. I tried inputDateParser, but it didn't work. Here is the jsfiddle



inputDateParser: function (value) {
value = value.split(/[:.]/);
return Date.UTC(
1970,
0,
1,
parseInt(value[0], 10),
parseInt(value[1], 10),
parseInt(value[2], 10),
parseInt(value[3], 10)
);
}


How do I get the data range to be correct: month of October 2018 according to the dates in CSV?
I should not see a whole year in the navigator, when I only have data for October.
Thanks much appreciated










share|improve this question





























    0














    I have a CSV file with following format:



    <pre id="csv" style="display:none">
    DATES,WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER
    01/10/2018 00:00,25,16,13,1,0
    01/10/2018 01:00,24,5,9,3,2
    01/10/2018 02:00,28,6,17,0,6


    The data range is 01/10/2018 00:00 - 31/10/2018 00:00
    Interval is every hour.
    I am using highstock stacked column with 5 categories: WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER.
    My problem is, that the highstock navigator displays the data incorrectly. I think I have to customise property in range selector or navigator, but I can't find any documentation online. I tried inputDateParser, but it didn't work. Here is the jsfiddle



    inputDateParser: function (value) {
    value = value.split(/[:.]/);
    return Date.UTC(
    1970,
    0,
    1,
    parseInt(value[0], 10),
    parseInt(value[1], 10),
    parseInt(value[2], 10),
    parseInt(value[3], 10)
    );
    }


    How do I get the data range to be correct: month of October 2018 according to the dates in CSV?
    I should not see a whole year in the navigator, when I only have data for October.
    Thanks much appreciated










    share|improve this question



























      0












      0








      0







      I have a CSV file with following format:



      <pre id="csv" style="display:none">
      DATES,WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER
      01/10/2018 00:00,25,16,13,1,0
      01/10/2018 01:00,24,5,9,3,2
      01/10/2018 02:00,28,6,17,0,6


      The data range is 01/10/2018 00:00 - 31/10/2018 00:00
      Interval is every hour.
      I am using highstock stacked column with 5 categories: WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER.
      My problem is, that the highstock navigator displays the data incorrectly. I think I have to customise property in range selector or navigator, but I can't find any documentation online. I tried inputDateParser, but it didn't work. Here is the jsfiddle



      inputDateParser: function (value) {
      value = value.split(/[:.]/);
      return Date.UTC(
      1970,
      0,
      1,
      parseInt(value[0], 10),
      parseInt(value[1], 10),
      parseInt(value[2], 10),
      parseInt(value[3], 10)
      );
      }


      How do I get the data range to be correct: month of October 2018 according to the dates in CSV?
      I should not see a whole year in the navigator, when I only have data for October.
      Thanks much appreciated










      share|improve this question















      I have a CSV file with following format:



      <pre id="csv" style="display:none">
      DATES,WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER
      01/10/2018 00:00,25,16,13,1,0
      01/10/2018 01:00,24,5,9,3,2
      01/10/2018 02:00,28,6,17,0,6


      The data range is 01/10/2018 00:00 - 31/10/2018 00:00
      Interval is every hour.
      I am using highstock stacked column with 5 categories: WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER.
      My problem is, that the highstock navigator displays the data incorrectly. I think I have to customise property in range selector or navigator, but I can't find any documentation online. I tried inputDateParser, but it didn't work. Here is the jsfiddle



      inputDateParser: function (value) {
      value = value.split(/[:.]/);
      return Date.UTC(
      1970,
      0,
      1,
      parseInt(value[0], 10),
      parseInt(value[1], 10),
      parseInt(value[2], 10),
      parseInt(value[3], 10)
      );
      }


      How do I get the data range to be correct: month of October 2018 according to the dates in CSV?
      I should not see a whole year in the navigator, when I only have data for October.
      Thanks much appreciated







      csv highcharts navigator






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 21:57

























      asked Nov 20 at 16:26









      marialaustsen

      186




      186
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You would need to format the dates correctly, it can be done using the beforeParse callback function, like this:



          data: {
          csv: document.getElementById('csv').innerHTML,
          beforeParse: function(e) {
          let csv = e.split('n'); //split by newline
          let processedTable =
          processedTable.push(csv[0].split(','))
          for (let i = 1; i < csv.length; i++) {
          let row = csv[i].split(',');
          if (row.length != 6) //skip empty rows or rows with more/less columns
          continue;
          let date = row[0].split(' ')[0].split('/')
          let time = row[0].split(' ')[1].split(':')

          processedTable.push(
          [(new Date(date[2], date[1] - 1, date[0], time[0], time[1], 0)).getTime(), //get the timestamp for the date
          parseInt(row[1]),
          parseInt(row[2]),
          parseInt(row[3]),
          parseInt(row[4]),
          parseInt(row[5])
          ].join(',')
          )
          }
          return processedTable.join('n') //join the array into a string again
          },
          },


          Every row is parsed, by splitting it apart, the date is found, and milliseconds since 1970 is returned by getTime(). Then we join the cells into strings, and lastly the rows into a long string. The reason we convert this back into a string, is because highcharts is going to read it in from a string.



          Working JSFiddle example: https://jsfiddle.net/ewolden/spmtgv3a/



          API on beforeParse: https://api.highcharts.com/highcharts/data.beforeParse






          share|improve this answer

















          • 1




            thank you. I have updated jsfiddle: jsfiddle.net/marialaustsen/tumfhsjb Now also with rangeSelector button types.
            – marialaustsen
            Nov 22 at 11:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397345%2fhow-to-process-csv-data-datetime-month-week-day-hour-in-highstock-highchart%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You would need to format the dates correctly, it can be done using the beforeParse callback function, like this:



          data: {
          csv: document.getElementById('csv').innerHTML,
          beforeParse: function(e) {
          let csv = e.split('n'); //split by newline
          let processedTable =
          processedTable.push(csv[0].split(','))
          for (let i = 1; i < csv.length; i++) {
          let row = csv[i].split(',');
          if (row.length != 6) //skip empty rows or rows with more/less columns
          continue;
          let date = row[0].split(' ')[0].split('/')
          let time = row[0].split(' ')[1].split(':')

          processedTable.push(
          [(new Date(date[2], date[1] - 1, date[0], time[0], time[1], 0)).getTime(), //get the timestamp for the date
          parseInt(row[1]),
          parseInt(row[2]),
          parseInt(row[3]),
          parseInt(row[4]),
          parseInt(row[5])
          ].join(',')
          )
          }
          return processedTable.join('n') //join the array into a string again
          },
          },


          Every row is parsed, by splitting it apart, the date is found, and milliseconds since 1970 is returned by getTime(). Then we join the cells into strings, and lastly the rows into a long string. The reason we convert this back into a string, is because highcharts is going to read it in from a string.



          Working JSFiddle example: https://jsfiddle.net/ewolden/spmtgv3a/



          API on beforeParse: https://api.highcharts.com/highcharts/data.beforeParse






          share|improve this answer

















          • 1




            thank you. I have updated jsfiddle: jsfiddle.net/marialaustsen/tumfhsjb Now also with rangeSelector button types.
            – marialaustsen
            Nov 22 at 11:24
















          1














          You would need to format the dates correctly, it can be done using the beforeParse callback function, like this:



          data: {
          csv: document.getElementById('csv').innerHTML,
          beforeParse: function(e) {
          let csv = e.split('n'); //split by newline
          let processedTable =
          processedTable.push(csv[0].split(','))
          for (let i = 1; i < csv.length; i++) {
          let row = csv[i].split(',');
          if (row.length != 6) //skip empty rows or rows with more/less columns
          continue;
          let date = row[0].split(' ')[0].split('/')
          let time = row[0].split(' ')[1].split(':')

          processedTable.push(
          [(new Date(date[2], date[1] - 1, date[0], time[0], time[1], 0)).getTime(), //get the timestamp for the date
          parseInt(row[1]),
          parseInt(row[2]),
          parseInt(row[3]),
          parseInt(row[4]),
          parseInt(row[5])
          ].join(',')
          )
          }
          return processedTable.join('n') //join the array into a string again
          },
          },


          Every row is parsed, by splitting it apart, the date is found, and milliseconds since 1970 is returned by getTime(). Then we join the cells into strings, and lastly the rows into a long string. The reason we convert this back into a string, is because highcharts is going to read it in from a string.



          Working JSFiddle example: https://jsfiddle.net/ewolden/spmtgv3a/



          API on beforeParse: https://api.highcharts.com/highcharts/data.beforeParse






          share|improve this answer

















          • 1




            thank you. I have updated jsfiddle: jsfiddle.net/marialaustsen/tumfhsjb Now also with rangeSelector button types.
            – marialaustsen
            Nov 22 at 11:24














          1












          1








          1






          You would need to format the dates correctly, it can be done using the beforeParse callback function, like this:



          data: {
          csv: document.getElementById('csv').innerHTML,
          beforeParse: function(e) {
          let csv = e.split('n'); //split by newline
          let processedTable =
          processedTable.push(csv[0].split(','))
          for (let i = 1; i < csv.length; i++) {
          let row = csv[i].split(',');
          if (row.length != 6) //skip empty rows or rows with more/less columns
          continue;
          let date = row[0].split(' ')[0].split('/')
          let time = row[0].split(' ')[1].split(':')

          processedTable.push(
          [(new Date(date[2], date[1] - 1, date[0], time[0], time[1], 0)).getTime(), //get the timestamp for the date
          parseInt(row[1]),
          parseInt(row[2]),
          parseInt(row[3]),
          parseInt(row[4]),
          parseInt(row[5])
          ].join(',')
          )
          }
          return processedTable.join('n') //join the array into a string again
          },
          },


          Every row is parsed, by splitting it apart, the date is found, and milliseconds since 1970 is returned by getTime(). Then we join the cells into strings, and lastly the rows into a long string. The reason we convert this back into a string, is because highcharts is going to read it in from a string.



          Working JSFiddle example: https://jsfiddle.net/ewolden/spmtgv3a/



          API on beforeParse: https://api.highcharts.com/highcharts/data.beforeParse






          share|improve this answer












          You would need to format the dates correctly, it can be done using the beforeParse callback function, like this:



          data: {
          csv: document.getElementById('csv').innerHTML,
          beforeParse: function(e) {
          let csv = e.split('n'); //split by newline
          let processedTable =
          processedTable.push(csv[0].split(','))
          for (let i = 1; i < csv.length; i++) {
          let row = csv[i].split(',');
          if (row.length != 6) //skip empty rows or rows with more/less columns
          continue;
          let date = row[0].split(' ')[0].split('/')
          let time = row[0].split(' ')[1].split(':')

          processedTable.push(
          [(new Date(date[2], date[1] - 1, date[0], time[0], time[1], 0)).getTime(), //get the timestamp for the date
          parseInt(row[1]),
          parseInt(row[2]),
          parseInt(row[3]),
          parseInt(row[4]),
          parseInt(row[5])
          ].join(',')
          )
          }
          return processedTable.join('n') //join the array into a string again
          },
          },


          Every row is parsed, by splitting it apart, the date is found, and milliseconds since 1970 is returned by getTime(). Then we join the cells into strings, and lastly the rows into a long string. The reason we convert this back into a string, is because highcharts is going to read it in from a string.



          Working JSFiddle example: https://jsfiddle.net/ewolden/spmtgv3a/



          API on beforeParse: https://api.highcharts.com/highcharts/data.beforeParse







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 8:39









          ewolden

          4,11131125




          4,11131125








          • 1




            thank you. I have updated jsfiddle: jsfiddle.net/marialaustsen/tumfhsjb Now also with rangeSelector button types.
            – marialaustsen
            Nov 22 at 11:24














          • 1




            thank you. I have updated jsfiddle: jsfiddle.net/marialaustsen/tumfhsjb Now also with rangeSelector button types.
            – marialaustsen
            Nov 22 at 11:24








          1




          1




          thank you. I have updated jsfiddle: jsfiddle.net/marialaustsen/tumfhsjb Now also with rangeSelector button types.
          – marialaustsen
          Nov 22 at 11:24




          thank you. I have updated jsfiddle: jsfiddle.net/marialaustsen/tumfhsjb Now also with rangeSelector button types.
          – marialaustsen
          Nov 22 at 11:24


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397345%2fhow-to-process-csv-data-datetime-month-week-day-hour-in-highstock-highchart%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin