How do I create Bar or Pie charts using an external CSV file?

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Roman on 1st August 2013
I did not find in your samples the case when I can use the external file as a data source. In particular, I need to query the SQL server and build the pie charts. ideally, it would be a one script but, so far, I use the SQL reporting services to generate the CVS or XML file that can be used a s a source file for data.
Any options with your software? If yes, any sample?
Posted by RGraph support on 2nd August 2013
Hi there,

To query the database you'd need to use whatever server-side scripting language that (it sounds like) you're already using (ASP? PHP?). Then you can put the data, in CSV form, in a DIV in the page. That way you can get to the data with JavaScript. There's a demo of a Bipolar here which extracts its left data and right data from a hidden DIV. I'd reccommend that you don't set the DIV as hidden until you have the chart up and running.

You could also use AJAX to request an XML - but that's far more involved - so if possible I'd advise going down the CSV route if you can.

Richard, RGraph Support
Posted by Roman on 2nd August 2013
Elegant, but it is still not a pure "external file" solution. You have the data as a text with data being separated by coma and the labels assigned manually. How about this CSV file?

RDN/Generic Dropper!qk,6
RDN/Generic Exploit!1m3,9
RDN/Generic PWS.y!tm,24

1. You don't know the label names in advance.
2. Your code does not contain the reference to the external file as it is done in the Highcharts solution, for instance.
Posted by RGraph support on 2nd August 2013
Hi there,

How you handle the content of the CSV file is up to you. So you can parse it and then use it as labels, data, a combination of the two - whatever you wish.

You may find it easier to use JSON. With JSON you can specify labels and data quite easily.

There's basic examples of both in conjunction with AJAX here:

RGraph Support
Posted by RGraph support on 2nd August 2013
Hi there,

Also - I'll add that there's a much more versatile and complete class that handles CSV files/data planned for the next release. This will make handling CSV files easier.

Richard, RGraph support
Posted by Roman on 8th August 2013
Thank you! I'll test the script with my data and look forward to the next release.

Posted by RGraph support on 8th August 2013
Hi there,

The docs page about the CSV reader will be here when its live:

(it's not there yet)

Richard, RGraph support

Add a reply

« Back to message list