1
votes

I have created a bar chart using google charts, this is a CORE Chart

I have tried getting the bar chart to change colours and adding an additional tooltip information to it, so that the tooltip shows a bit more information

I have gone through the google documentation and i cant see what i am doing wrong

For easy reading this is the output of my code on the source

 google.charts.load("current", {packages:['corechart']});
        google.charts.setOnLoadCallback(drawChart);
         function drawChart() {
             var exams = [["Date", "Score",({type: 'string', role: 'tooltip'})], ["18 Oct", 39,"TEST"], ["26 Oct", 20,"TEST"], ["26 Oct", 0,"TEST"], ["27 Oct", 0,"TEST"], ["27 Oct", 0,"TEST"]];
             if(exams.length > 1){
             var data = google.visualization.arrayToDataTable(exams);
             var view = new google.visualization.DataView(data);
             view.setColumns([0, 1]);
             var options = {
                 title: "Results",
                 width: 1170,
                 height: 700,
                 bar: {groupWidth: "95%"},
                 legend: { position: "none" }
             };
             var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
             chart.draw(view, options);
             }
                else{
                    $("#columnchart_values").html('No Data found to show graph');
                }
         }

This is the google documentation i have been following, its slightly different to mine as i am getting my data from a database, but it should give the same output.

I have gone through many examples and i am replicating them as close as possible and just not having any luck

https://developers.google.com/chart/interactive/docs/customizing_tooltip_content

I also have the exact same problem with color, i cant get colors on bar charts to change both having the same problem that it just doesn't do anything

Am i missing something??

1

1 Answers

1
votes

the tooltip column is not being included in the data view.

view.setColumns([0, 1]);

to add the tooltip...

view.setColumns([0, 1, 2]);