I've seen some posts about this but it's still unclear to me how to get this done. I have a Django application that queries a SQL database. I bring this data in and convert it from a pandas dataframe to a JSON format:
tempdata = json.dumps(d, cls=DjangoJSONEncoder)
return render(request, 'notes/gantt.html', {'data': tempdata})
JSON looks like this:
[["id", "title", "created", "est_completion"], ["3", "Add new Security Group", "2022-04-25", "2022-05-05"]]
I tried to pass this into the google chart visual but I'm getting an error:
Invalid data table format: column #2 must be of type 'date,number,datetime'.
Its my understanding the date format is specific to google charts and needs to be set to new Date(2016, 11, 31)
My question is how can i do that? Is there a for loop I have to run? or is there an easier more straightforward way to do it?
google.charts.load("current", {packages: ["timeline"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById("timeline");
var chart = new google.visualization.Timeline(container);
var dataTable = google.visualization.arrayToDataTable({{ data|safe }});
var options = {
timeline: {showRowLabels: false},
animation: {
startup: true,
duration: 1000,
easing: "in"
},
avoidOverlappingGridLines: true,
backgroundColor: "#e8e7e7",
};
chart.draw(dataTable, options);