Go utility for converting JSON data type to Google Chart structure so that DataTable can understand.
This utility export the types needed for creating Data Parameters needed to draw the chart
-
Import Chart
import ( GoogleChart "github.com/prabdeb/go-google-chart" )
-
Initiate the chart object with Columns
zooData := GoogleChart.Chart{ Cols: []GoogleChart.ColsType{ GoogleChart.ColsType{ Label: "Animals", Type: "string", }, GoogleChart.ColsType{ Label: "Count", Type: "number", }, }, }
-
Insert into Rows
for animal, count := range zooDatabase["zoo_name"].(map[string]interface{}) { zooData.Rows = append(zooData.Rows, GoogleChart.RowType{ C: []GoogleChart.RowCType{ GoogleChart.RowCType{ V: animal, }, GoogleChart.RowCType{ V: count, }, }, }) }