I'm basing this answer on a solution I found here: http://jsfiddle.net/asgallant/6Y8jF/2/
The gist is to hide Google's legend and build your own. First, disable the built-in legend by passing legend: {position: 'none'}
in as one of the options to chart.draw
.
In your addDiv
function that creates the holder div for your chart, add a second element to hold your legend.
function addDiv(parent_id, div_id) {
$("#" + parent_id).append('<div id="' + div_id + '" class="chart-chart"></div><ul id="legend_' + div_id + '" class="chart-legend"></ul>');
}
Then, in your drawChart
function, build the legend:
function drawChart(chart, original_table,
x_attr, y_attr, x_axis_lbl, y_axis_lbl, x_min_max,
div_id) { //pass div_id to this function to be able to get legend element
var google_table = allSeriesToGoogleTable(original_table,
x_attr, y_attr, ranking_titles);
var colors = ["#3366cc","#dc3912","#ff9900"]; //use whatever colors you like
var options = {'chartArea':{width:"60%"},
vAxis: {'title': y_axis_lbl}, 'hAxis': {'title': x_axis_lbl},
'interpolateNulls':true,
colors: colors, //use the same colors for the chart and the legend
legend: {position: 'none'} //hide default legend
};
var legend = $('#legend_' + div_id);
for (var i = 1; i < ranking_titles.length; i++) {
var li = $('<li></li>'),
marker = $('<div class="legendMarker"></div>'),
explanation = $('<span></span>');
explanation.text(ranking_titles[i]); // legend marker text
marker.css( {backgroundColor: colors[i-1]} ); //marker color
li.append(marker).append(explanation);
legend.append(li);
}
if ( ! x_min_max === undefined )
//do something
chart.draw( google_table, options );
// add the data table to the chart
chart.google_table = google_table;
}
Of course, make sure you include the CSS from the fiddle as well:
.chart-chart {
float: left;
}
.chart-legend {
margin: 30px 0 0 0;
float: left;
list-style: none;
}
div.legendMarker {
height: 1em;
width: 1em;
display: inline-block;
margin: 0 5px 0 0;
}
Since you couldn't get your code into fiddle, this is untested, but it should get you 99% of the way there.