Fetching and processing data with semicolon delimiters and no headersConvert form data to JavaScript object with jQueryWhat are the rules for JavaScript's automatic semicolon insertion (ASI)?How does data binding work in AngularJS?How does Access-Control-Allow-Origin header work?offsetting an html anchor to adjust for fixed headerHow can I access and process nested objects, arrays or JSON?Fetch: POST json dataUsing an authorization header with Fetch in React NativeFetch API with CookieNo 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API

How do I separate enchants from items?

Can one block with a protection from color creature?

How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant

Delete elements less than the last largest element

US citizen traveling with Peruvian passport

Where are the Wazirs?

Can the word "desk" be used as a verb?

What exactly is a "murder hobo"?

Why do people prefer metropolitan areas, considering monsters and villains?

Would denouncing cheaters from an exam make me less likely to receive penalties?

Array or vector? Two dimensional array or matrix?

How to understand flavors and when to use combination of them?

Why did Robert F. Kennedy loathe Lyndon B. Johnson?

Appropriate conduit for several data cables underground over 300' run

Writing an ace/aro character?

stuck in/at beta

Blocks from @ jafe

Computer name naming convention for security

What is the meaning of "prairie-dog" in this sentence?

Why am I getting unevenly-spread results when using $RANDOM?

Tesco's Burger Relish Best Before End date number

Users forgotting to regenerate PDF before sending it

What are the effects of abstaining from eating a certain flavor?

Is there a formal/better word than "skyrocket" for the given context?



Fetching and processing data with semicolon delimiters and no headers


Convert form data to JavaScript object with jQueryWhat are the rules for JavaScript's automatic semicolon insertion (ASI)?How does data binding work in AngularJS?How does Access-Control-Allow-Origin header work?offsetting an html anchor to adjust for fixed headerHow can I access and process nested objects, arrays or JSON?Fetch: POST json dataUsing an authorization header with Fetch in React NativeFetch API with CookieNo 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I have had some trouble understanding the D3.JS fetch documentation:



My data source is:



20180601 000000;1.168200;1.168240;1.168140;1.168230;0;
20180601 000100;1.168220;1.168230;1.168190;1.168190;0;
20180601 000200;1.168180;1.168180;1.168080;1.168120;0;
20180601 000300;1.168130;1.168160;1.168130;1.168140;0;


where the format is:



%Y%m%d %H%M%S;number1;number2;number3;number4;number5;


My difficulties are:



  1. Adding headers to the data

  2. Dealing with semicolons as the delimiter instead of commas

1) From what I can work out I need to read the file without parsing it, then join a text string to the beginning of the file then finally parse the data.



d3.text(data.csv, function(error, textString));

var headers = ["date","time","data1","data2"].join("t");

d3.csv.parse(headers + textString);


2) I can use the dsv format and set the delimiter to semicolons?



d3.dsv(";", "text/plain")


The rough code I ended up with is:



var time_parse = d3.timeParse( '%Y%m%d %H%M%S');
var time_format = d3.timeFormat('%H%M');

d3.text(data.csv, function(error, textString)

var headers = ["time;number1;number2;number3;number4;number5;"].join("t")

d3.csv.parse(headers + textString)

d3.dsv(";", "text/plain")

data.forEach(function(e,i)
data[i].time = time_parse(e.date);
)

)


Ideally I want the data to look like this when logged:



Time, Number1, Number2, Number3, Number4, Number5
00:00, 1.168200, 1.168240, 1.168140, 1.168230, 0
etc


What is the flaw in my thinking and can anyone offer advice on how to solve my problem and similar problems in the future?



Note: I am new to Javascript and d3 and although I have been able to work through most of the documentation involving drawing svgs, creating axis and scales, transitions etc with no problems, I am struggling to get my head around actually getting data from real sources (e.g the internet) and processing them into something workable. Please heavily critique anything I have said and offer advice, I want to learn.










share|improve this question






























    3















    I have had some trouble understanding the D3.JS fetch documentation:



    My data source is:



    20180601 000000;1.168200;1.168240;1.168140;1.168230;0;
    20180601 000100;1.168220;1.168230;1.168190;1.168190;0;
    20180601 000200;1.168180;1.168180;1.168080;1.168120;0;
    20180601 000300;1.168130;1.168160;1.168130;1.168140;0;


    where the format is:



    %Y%m%d %H%M%S;number1;number2;number3;number4;number5;


    My difficulties are:



    1. Adding headers to the data

    2. Dealing with semicolons as the delimiter instead of commas

    1) From what I can work out I need to read the file without parsing it, then join a text string to the beginning of the file then finally parse the data.



    d3.text(data.csv, function(error, textString));

    var headers = ["date","time","data1","data2"].join("t");

    d3.csv.parse(headers + textString);


    2) I can use the dsv format and set the delimiter to semicolons?



    d3.dsv(";", "text/plain")


    The rough code I ended up with is:



    var time_parse = d3.timeParse( '%Y%m%d %H%M%S');
    var time_format = d3.timeFormat('%H%M');

    d3.text(data.csv, function(error, textString)

    var headers = ["time;number1;number2;number3;number4;number5;"].join("t")

    d3.csv.parse(headers + textString)

    d3.dsv(";", "text/plain")

    data.forEach(function(e,i)
    data[i].time = time_parse(e.date);
    )

    )


    Ideally I want the data to look like this when logged:



    Time, Number1, Number2, Number3, Number4, Number5
    00:00, 1.168200, 1.168240, 1.168140, 1.168230, 0
    etc


    What is the flaw in my thinking and can anyone offer advice on how to solve my problem and similar problems in the future?



    Note: I am new to Javascript and d3 and although I have been able to work through most of the documentation involving drawing svgs, creating axis and scales, transitions etc with no problems, I am struggling to get my head around actually getting data from real sources (e.g the internet) and processing them into something workable. Please heavily critique anything I have said and offer advice, I want to learn.










    share|improve this question


























      3












      3








      3








      I have had some trouble understanding the D3.JS fetch documentation:



      My data source is:



      20180601 000000;1.168200;1.168240;1.168140;1.168230;0;
      20180601 000100;1.168220;1.168230;1.168190;1.168190;0;
      20180601 000200;1.168180;1.168180;1.168080;1.168120;0;
      20180601 000300;1.168130;1.168160;1.168130;1.168140;0;


      where the format is:



      %Y%m%d %H%M%S;number1;number2;number3;number4;number5;


      My difficulties are:



      1. Adding headers to the data

      2. Dealing with semicolons as the delimiter instead of commas

      1) From what I can work out I need to read the file without parsing it, then join a text string to the beginning of the file then finally parse the data.



      d3.text(data.csv, function(error, textString));

      var headers = ["date","time","data1","data2"].join("t");

      d3.csv.parse(headers + textString);


      2) I can use the dsv format and set the delimiter to semicolons?



      d3.dsv(";", "text/plain")


      The rough code I ended up with is:



      var time_parse = d3.timeParse( '%Y%m%d %H%M%S');
      var time_format = d3.timeFormat('%H%M');

      d3.text(data.csv, function(error, textString)

      var headers = ["time;number1;number2;number3;number4;number5;"].join("t")

      d3.csv.parse(headers + textString)

      d3.dsv(";", "text/plain")

      data.forEach(function(e,i)
      data[i].time = time_parse(e.date);
      )

      )


      Ideally I want the data to look like this when logged:



      Time, Number1, Number2, Number3, Number4, Number5
      00:00, 1.168200, 1.168240, 1.168140, 1.168230, 0
      etc


      What is the flaw in my thinking and can anyone offer advice on how to solve my problem and similar problems in the future?



      Note: I am new to Javascript and d3 and although I have been able to work through most of the documentation involving drawing svgs, creating axis and scales, transitions etc with no problems, I am struggling to get my head around actually getting data from real sources (e.g the internet) and processing them into something workable. Please heavily critique anything I have said and offer advice, I want to learn.










      share|improve this question
















      I have had some trouble understanding the D3.JS fetch documentation:



      My data source is:



      20180601 000000;1.168200;1.168240;1.168140;1.168230;0;
      20180601 000100;1.168220;1.168230;1.168190;1.168190;0;
      20180601 000200;1.168180;1.168180;1.168080;1.168120;0;
      20180601 000300;1.168130;1.168160;1.168130;1.168140;0;


      where the format is:



      %Y%m%d %H%M%S;number1;number2;number3;number4;number5;


      My difficulties are:



      1. Adding headers to the data

      2. Dealing with semicolons as the delimiter instead of commas

      1) From what I can work out I need to read the file without parsing it, then join a text string to the beginning of the file then finally parse the data.



      d3.text(data.csv, function(error, textString));

      var headers = ["date","time","data1","data2"].join("t");

      d3.csv.parse(headers + textString);


      2) I can use the dsv format and set the delimiter to semicolons?



      d3.dsv(";", "text/plain")


      The rough code I ended up with is:



      var time_parse = d3.timeParse( '%Y%m%d %H%M%S');
      var time_format = d3.timeFormat('%H%M');

      d3.text(data.csv, function(error, textString)

      var headers = ["time;number1;number2;number3;number4;number5;"].join("t")

      d3.csv.parse(headers + textString)

      d3.dsv(";", "text/plain")

      data.forEach(function(e,i)
      data[i].time = time_parse(e.date);
      )

      )


      Ideally I want the data to look like this when logged:



      Time, Number1, Number2, Number3, Number4, Number5
      00:00, 1.168200, 1.168240, 1.168140, 1.168230, 0
      etc


      What is the flaw in my thinking and can anyone offer advice on how to solve my problem and similar problems in the future?



      Note: I am new to Javascript and d3 and although I have been able to work through most of the documentation involving drawing svgs, creating axis and scales, transitions etc with no problems, I am struggling to get my head around actually getting data from real sources (e.g the internet) and processing them into something workable. Please heavily critique anything I have said and offer advice, I want to learn.







      javascript d3.js fetch-api import-from-csv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 22:24









      Brian Tompsett - 汤莱恩

      4,38214 gold badges40 silver badges107 bronze badges




      4,38214 gold badges40 silver badges107 bronze badges










      asked Jul 10 '18 at 21:19









      NeilCNeilC

      182 bronze badges




      182 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          It's not clear what version of d3 you are using, you reference the fetch API, but some of the code you have looks like d3v3 and v4 in the question code (which could be the problem) which doesn't use the fetch API. In any event, I'll go through v5, but also versions 4 and 3.



          In all of these your thoughts look pretty close based on the code blocks you have. We need to:



          • we read in the dsv as text,

          • add headers (with an end of line n),

          • and run everything through a dsv format function that will use a ; as a delimiter.

          no need for d3.csv.parse though as in your question code block



          In all the below I drop the date formatting for simplicity (oops, left it in the v5 demo).



          Because of the use of d3-fetch module in d3v5, this approach is a bit different than the more closely related d3v3/v4 (closely related in that they both use the d3-request module, otherwise there's a fair bit of difference).



          d3-fetch: d3v5



          With d3v5, using the d3-fetch module the process could look like:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv").then(function(text)
          var data = dsv.parse(headers+text);

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v4



          There's a bit more flexibility with d3v4 for this.



          If we look at the API docs, we see that d3.csv is equivalent to:



          d3.request(url)
          .mimeType("text/csv")
          .response(function(xhr) return d3.csvParse(xhr.responseText, row); );


          (docs)



          So if we create a new format with d3.dsvFormat we can run the content through the format and get our data, we can also tack on the headers in this process, all in one step:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.request("dsv.dsv")
          .mimeType("text/plain")
          .response(function(data) return dsv.parse(headers + data.response) )
          .get(function(data)
          // use data here:
          console.log(data);
          console.log(data.columns);
          );


          Example



          This might be the more atypical approach, so we could emulate the way I did it with v5 above:



          var psv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,data)
          var data = psv.parse(headers + data.reponse)

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v3



          As with the second option in d3v4 above and d3v5, we can parse in text and then run it through the dsv format function (here we only need to account for changes in d3 namespace between v3/v4):



          var dsv = d3.dsv(";","text/plain");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,text)
          var data = dsv.parse(headers+text);
          console.log(data);
          // console.log(data.columns) // -> no columns property in v3
          )


          Example



          Note



          The ; at the end of each row will create an empty column as a value is expected after it before the next row.






          share|improve this answer























          • Thank you so much for the detailed reply - it's been really helpful in solving my problem and improving my understanding

            – NeilC
            Jul 11 '18 at 9:14










          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%2f51274040%2ffetching-and-processing-data-with-semicolon-delimiters-and-no-headers%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














          It's not clear what version of d3 you are using, you reference the fetch API, but some of the code you have looks like d3v3 and v4 in the question code (which could be the problem) which doesn't use the fetch API. In any event, I'll go through v5, but also versions 4 and 3.



          In all of these your thoughts look pretty close based on the code blocks you have. We need to:



          • we read in the dsv as text,

          • add headers (with an end of line n),

          • and run everything through a dsv format function that will use a ; as a delimiter.

          no need for d3.csv.parse though as in your question code block



          In all the below I drop the date formatting for simplicity (oops, left it in the v5 demo).



          Because of the use of d3-fetch module in d3v5, this approach is a bit different than the more closely related d3v3/v4 (closely related in that they both use the d3-request module, otherwise there's a fair bit of difference).



          d3-fetch: d3v5



          With d3v5, using the d3-fetch module the process could look like:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv").then(function(text)
          var data = dsv.parse(headers+text);

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v4



          There's a bit more flexibility with d3v4 for this.



          If we look at the API docs, we see that d3.csv is equivalent to:



          d3.request(url)
          .mimeType("text/csv")
          .response(function(xhr) return d3.csvParse(xhr.responseText, row); );


          (docs)



          So if we create a new format with d3.dsvFormat we can run the content through the format and get our data, we can also tack on the headers in this process, all in one step:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.request("dsv.dsv")
          .mimeType("text/plain")
          .response(function(data) return dsv.parse(headers + data.response) )
          .get(function(data)
          // use data here:
          console.log(data);
          console.log(data.columns);
          );


          Example



          This might be the more atypical approach, so we could emulate the way I did it with v5 above:



          var psv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,data)
          var data = psv.parse(headers + data.reponse)

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v3



          As with the second option in d3v4 above and d3v5, we can parse in text and then run it through the dsv format function (here we only need to account for changes in d3 namespace between v3/v4):



          var dsv = d3.dsv(";","text/plain");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,text)
          var data = dsv.parse(headers+text);
          console.log(data);
          // console.log(data.columns) // -> no columns property in v3
          )


          Example



          Note



          The ; at the end of each row will create an empty column as a value is expected after it before the next row.






          share|improve this answer























          • Thank you so much for the detailed reply - it's been really helpful in solving my problem and improving my understanding

            – NeilC
            Jul 11 '18 at 9:14















          1














          It's not clear what version of d3 you are using, you reference the fetch API, but some of the code you have looks like d3v3 and v4 in the question code (which could be the problem) which doesn't use the fetch API. In any event, I'll go through v5, but also versions 4 and 3.



          In all of these your thoughts look pretty close based on the code blocks you have. We need to:



          • we read in the dsv as text,

          • add headers (with an end of line n),

          • and run everything through a dsv format function that will use a ; as a delimiter.

          no need for d3.csv.parse though as in your question code block



          In all the below I drop the date formatting for simplicity (oops, left it in the v5 demo).



          Because of the use of d3-fetch module in d3v5, this approach is a bit different than the more closely related d3v3/v4 (closely related in that they both use the d3-request module, otherwise there's a fair bit of difference).



          d3-fetch: d3v5



          With d3v5, using the d3-fetch module the process could look like:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv").then(function(text)
          var data = dsv.parse(headers+text);

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v4



          There's a bit more flexibility with d3v4 for this.



          If we look at the API docs, we see that d3.csv is equivalent to:



          d3.request(url)
          .mimeType("text/csv")
          .response(function(xhr) return d3.csvParse(xhr.responseText, row); );


          (docs)



          So if we create a new format with d3.dsvFormat we can run the content through the format and get our data, we can also tack on the headers in this process, all in one step:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.request("dsv.dsv")
          .mimeType("text/plain")
          .response(function(data) return dsv.parse(headers + data.response) )
          .get(function(data)
          // use data here:
          console.log(data);
          console.log(data.columns);
          );


          Example



          This might be the more atypical approach, so we could emulate the way I did it with v5 above:



          var psv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,data)
          var data = psv.parse(headers + data.reponse)

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v3



          As with the second option in d3v4 above and d3v5, we can parse in text and then run it through the dsv format function (here we only need to account for changes in d3 namespace between v3/v4):



          var dsv = d3.dsv(";","text/plain");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,text)
          var data = dsv.parse(headers+text);
          console.log(data);
          // console.log(data.columns) // -> no columns property in v3
          )


          Example



          Note



          The ; at the end of each row will create an empty column as a value is expected after it before the next row.






          share|improve this answer























          • Thank you so much for the detailed reply - it's been really helpful in solving my problem and improving my understanding

            – NeilC
            Jul 11 '18 at 9:14













          1












          1








          1







          It's not clear what version of d3 you are using, you reference the fetch API, but some of the code you have looks like d3v3 and v4 in the question code (which could be the problem) which doesn't use the fetch API. In any event, I'll go through v5, but also versions 4 and 3.



          In all of these your thoughts look pretty close based on the code blocks you have. We need to:



          • we read in the dsv as text,

          • add headers (with an end of line n),

          • and run everything through a dsv format function that will use a ; as a delimiter.

          no need for d3.csv.parse though as in your question code block



          In all the below I drop the date formatting for simplicity (oops, left it in the v5 demo).



          Because of the use of d3-fetch module in d3v5, this approach is a bit different than the more closely related d3v3/v4 (closely related in that they both use the d3-request module, otherwise there's a fair bit of difference).



          d3-fetch: d3v5



          With d3v5, using the d3-fetch module the process could look like:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv").then(function(text)
          var data = dsv.parse(headers+text);

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v4



          There's a bit more flexibility with d3v4 for this.



          If we look at the API docs, we see that d3.csv is equivalent to:



          d3.request(url)
          .mimeType("text/csv")
          .response(function(xhr) return d3.csvParse(xhr.responseText, row); );


          (docs)



          So if we create a new format with d3.dsvFormat we can run the content through the format and get our data, we can also tack on the headers in this process, all in one step:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.request("dsv.dsv")
          .mimeType("text/plain")
          .response(function(data) return dsv.parse(headers + data.response) )
          .get(function(data)
          // use data here:
          console.log(data);
          console.log(data.columns);
          );


          Example



          This might be the more atypical approach, so we could emulate the way I did it with v5 above:



          var psv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,data)
          var data = psv.parse(headers + data.reponse)

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v3



          As with the second option in d3v4 above and d3v5, we can parse in text and then run it through the dsv format function (here we only need to account for changes in d3 namespace between v3/v4):



          var dsv = d3.dsv(";","text/plain");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,text)
          var data = dsv.parse(headers+text);
          console.log(data);
          // console.log(data.columns) // -> no columns property in v3
          )


          Example



          Note



          The ; at the end of each row will create an empty column as a value is expected after it before the next row.






          share|improve this answer













          It's not clear what version of d3 you are using, you reference the fetch API, but some of the code you have looks like d3v3 and v4 in the question code (which could be the problem) which doesn't use the fetch API. In any event, I'll go through v5, but also versions 4 and 3.



          In all of these your thoughts look pretty close based on the code blocks you have. We need to:



          • we read in the dsv as text,

          • add headers (with an end of line n),

          • and run everything through a dsv format function that will use a ; as a delimiter.

          no need for d3.csv.parse though as in your question code block



          In all the below I drop the date formatting for simplicity (oops, left it in the v5 demo).



          Because of the use of d3-fetch module in d3v5, this approach is a bit different than the more closely related d3v3/v4 (closely related in that they both use the d3-request module, otherwise there's a fair bit of difference).



          d3-fetch: d3v5



          With d3v5, using the d3-fetch module the process could look like:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv").then(function(text)
          var data = dsv.parse(headers+text);

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v4



          There's a bit more flexibility with d3v4 for this.



          If we look at the API docs, we see that d3.csv is equivalent to:



          d3.request(url)
          .mimeType("text/csv")
          .response(function(xhr) return d3.csvParse(xhr.responseText, row); );


          (docs)



          So if we create a new format with d3.dsvFormat we can run the content through the format and get our data, we can also tack on the headers in this process, all in one step:



          var dsv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.request("dsv.dsv")
          .mimeType("text/plain")
          .response(function(data) return dsv.parse(headers + data.response) )
          .get(function(data)
          // use data here:
          console.log(data);
          console.log(data.columns);
          );


          Example



          This might be the more atypical approach, so we could emulate the way I did it with v5 above:



          var psv = d3.dsvFormat(";");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,data)
          var data = psv.parse(headers + data.reponse)

          console.log(data);
          console.log(data.columns);

          )


          Example



          d3-request: d3v3



          As with the second option in d3v4 above and d3v5, we can parse in text and then run it through the dsv format function (here we only need to account for changes in d3 namespace between v3/v4):



          var dsv = d3.dsv(";","text/plain");
          var headers = ["time;number1;number2;number3;number4;number5;n"]

          d3.text("dsv.dsv", function(error,text)
          var data = dsv.parse(headers+text);
          console.log(data);
          // console.log(data.columns) // -> no columns property in v3
          )


          Example



          Note



          The ; at the end of each row will create an empty column as a value is expected after it before the next row.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 10 '18 at 22:25









          Andrew ReidAndrew Reid

          20.8k4 gold badges27 silver badges50 bronze badges




          20.8k4 gold badges27 silver badges50 bronze badges












          • Thank you so much for the detailed reply - it's been really helpful in solving my problem and improving my understanding

            – NeilC
            Jul 11 '18 at 9:14

















          • Thank you so much for the detailed reply - it's been really helpful in solving my problem and improving my understanding

            – NeilC
            Jul 11 '18 at 9:14
















          Thank you so much for the detailed reply - it's been really helpful in solving my problem and improving my understanding

          – NeilC
          Jul 11 '18 at 9:14





          Thank you so much for the detailed reply - it's been really helpful in solving my problem and improving my understanding

          – NeilC
          Jul 11 '18 at 9:14








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51274040%2ffetching-and-processing-data-with-semicolon-delimiters-and-no-headers%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript