From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Graphing arrays

Solved!
Go to solution

Hey there Labview masters, a beginner here looking some guidance.  I have extracted data (strings) from a csv in the form of an array and now I want to graph them in a bar graph by quantity.  I have roughly 6000 countries in the column I want to graph, so if Peru is the most common country in the column, the bar graph will indicate that with the largest bar, the least common country will have the lowest, etc.  I've scoured youtube and havent come up with a solution yet. 

 

Bonus Round: As you can see from the fatalities column I want to extract, even though the correct column is chosen, all the data is messed up, grabbing elements from other columns.  Why is this? 

 

Thanks!

some pics if you dont want to download

BD.PNGFP.PNGexce.PNG

 

Download All
0 Kudos
Message 1 of 10
(3,934 Views)

Your fatalities column is not right because the "trigger" column has more than one value in some rows "nearest_places" column has a comma in the city name. So basically in those cases, all values get shifted to the right. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 2 of 10
(3,918 Views)

Hmm I understand what you are saying, but looking through the data for "trigger" I don't see any elements that have more than one value, no commas.  Am I blind?

 

EDIT: Just saw your edit.  Thank you!

0 Kudos
Message 3 of 10
(3,912 Views)

Right csv format view like this:

1.23, 4.56, "some,string"

1.23, some string, 4.56

 

P.S. Excel make and import incorrect csv file.

0 Kudos
Message 4 of 10
(3,902 Views)

Think you can expand on that a little?  Do I have to change the format of the document?

0 Kudos
Message 5 of 10
(3,853 Views)

I assume you are getting this data from a USGS website.  If you are able to download a tab delimited file rather than a comma delimited one, the commas in the city name won't affect the import.  If CSV is the only available format, you may need to create your own import function that ignores commas inside of double quotes.  Maybe there is a way to do this with the Read Delimited Spreadsheet function but I am not aware of it.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 6 of 10
(3,827 Views)

The column "near places" wasnt even needed for what I am doing, so I was able to just delete it and continue on.  Now that I have my data, I'm still having trouble graphing it by quantity.  Any functions you can point me to to help me out? 

0 Kudos
Message 7 of 10
(3,817 Views)

Trevor,

In your sample csv file, if the near_places column contains more than one location it is separated by quotes.

 

To parse the data correctly,  first you need to check if the line contains a double quote.

 

 Capture.PNG

Download All
0 Kudos
Message 8 of 10
(3,755 Views)
Solution
Accepted by topic author trevor322

@trevor322 wrote:

I have extracted data (strings) from a csv in the form of an array and now I want to graph them in a bar graph by quantity.  I have roughly 6000 countries in the column I want to graph, so if Peru is the most common country in the column, the bar graph will indicate that with the largest bar, the least common country will have the lowest, etc.  


Firstly, your data file seems corrupted, because there is a poorly formatted line (~644) without country (search for "milepost"). You might want to correct that or edit it out. There might be others.

 

The above solution seems overly complicated, so here's a simpler version. It basically replaces all commas with tabs unless they occur between quotes, then converts each line to a string array based on tab delimiters.

 

landslides.png

 

In the attached VI, I also show how you can use variant attributes to sum the total fatalities per country and display it in a sorted table. Modify as needed. (note that the corrupt line has a blank country and empty strings are not allowed as attribute name). A table seems better than a bar graph.

 

landslides-total.png

 

Message 9 of 10
(3,528 Views)

You're a champion.  Very clean work, I'm learning a lot about Labview just by having the examples laid out for me.  Thank you!

0 Kudos
Message 10 of 10
(3,520 Views)