Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing a Single Google Line Chart with multiple lines using JSON

I'm trying to draw a line chart from data received from mysql database. From the database I have these data

enter image description here

I want to draw a google line chart getting the x-axis as the sales date and the y-axis as the product_name. But I want multiple lines for each product, like this.

enter image description here

I can draw the chart for a single product. But can't imagine how to do it for multiple products in the same chart. I'm using JSON to get data for the chart and using a MySQL database. Any help, tutorial would be appreciated. Thanks.

PS: I followed this tutorial for a single line chart. http://www.kometschuh.de/GoogleChartToolswithJSON.html

like image 665
kinath_ru Avatar asked Nov 12 '22 18:11

kinath_ru


1 Answers

According to the example and documentation here, you need to create the data portion of the charts like so:

        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses'],
          ['2004',  1000,      400],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540]
        ]);

['Year', 'Sales', 'Expenses'] is [x-axis, line 1, line 2, ... lineX]

then each subsequent array is the corresponding data.

In the example you've linked it shows the data as ['day', 'counts'], which corresponds to the above format.

You can see a representation of this right under the heading of Data Format here

like image 150
Chase Avatar answered Nov 15 '22 09:11

Chase