I'm using the d3 library trying to do a geo chart with LWC. To do so I need a csv file with my values in it like the example bellow

var promises = [];

My JSON is already a static ressource in my org but for the CSV it will be the result of a SOQL query with my values. Something like that :

List<Account> listAcc = [SELECT City, CityCode__c, Value1__c, Value2__c FROM Account]

I tried creating a list of String adding the value of my list of Account but the result isn't what I was expected. The CSV file should looks like this :

CODE_REG, Name_REG, CODE_State, Name_State, Value1, Value2
my values seperated by coma

How can I do the trick without exporting a CSV file each time I want to retrieve my data through my lwc component implementing d3 library ?

  • 1
    IMO It would be ideal to use the list of objects. or whatever the JSON structure accepted by Geo charts instead of creating csv files. Commented Nov 25, 2020 at 17:12
  • There's a JSON and a CSV used by Geo charts. I already have the JSON of the chart I downloaded from web. Now I need to create a String accepted by d3 in a CSV format with the data from Salesforce, and I don't really know how to do it.
    – Jack
    Commented Nov 25, 2020 at 17:36

1 Answer 1


I would recommend just using papaparse. Once imported, you can have the list of objects returned from the wire call and passed directly into Papaparse, which will output a CSV for you.

let csv = Papa.unparse(accountData);

Since you're already using D3, I presume you're familiar with importing scripts to LWC. All you need is a bit of help, and that library can do it pretty easy.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .