Android Question Creating a bar chart using data from files.

Izmirov.Yaminovich

Member
Licensed User
Longtime User
Hi,

Anybody knows how to create a bar chart that can link to the sets of data's that I have in the csv files?

Something like this
upload_2016-7-12_14-42-56.png


Thanks
 

Izmirov.Yaminovich

Member
Licensed User
Longtime User
Creating a chart is not the problem. The problem is to retrieve the datas from the csv file to make a bar chart. say I have a sets of datas in a csv files like this:
upload_2016-7-12_16-50-9.png

And I would like to plot a bar chart using data's from the files. Do you know how can I do it?
 
Upvote 0

Izmirov.Yaminovich

Member
Licensed User
Longtime User
Hi Erel, how do I link the datas from the file?
B4X:
Private Sub CreateBarChartData (cols As List, rows As List)
    cols.Add(CreateColumn("", "Location", "string"))
    cols.Add(CreateColumn("", "Volume", "number"))
    cols.Add(CreateColumn("", "Expenses", "number"))
    rows.Add(CreateRow(Array As Object("1", 34, 40)))
    rows.Add(CreateRow(Array As Object("2", 17, 46)))
End Sub

Instead of keying it in the code, are there anyway to just link it up from the files? For example, the value in A1 in the file is 34, what should I write to just makes it automatically links it instead of keying in 34?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Yes, when I say automatic it means that's the function of that the code should do. Do you know the code or link I can read about?

Read thru this thread ...https://www.b4x.com/android/forum/threads/csv-contain-names-of-variables.63604/#content

Although it has no connection to creating charts ... If you study it , It will demonstrate how to read your csv file to a list , then iterate thru that list to retrieve your data.
You can then reference that data in your chart statements instead of manually typing in the data.
 
Upvote 0

Izmirov.Yaminovich

Member
Licensed User
Longtime User
For the google charts, I realized that there's a need to copy down the template.html into the files folder. The codes in the files are as below:

B4X:
<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable($DATA$);

        var options = $OPTIONS$

        var chart = new google.visualization.$TYPE$(document.getElementById('chart'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart" style="width: 100%; height: 100%;"></div>
  </body>
</html>

Is it possible for me to change the HTML code in there that can allow me to link it to the data's that I have?
 
Upvote 0
Top