Here’s my basic code to draw column chart using Google Charts API:
<meta charset="UTF-8">
<title>Google Charts</title>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages: ["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart()
{
var my_chart = document.getElementById("my_chart");
var data = google.visualization.arrayToDataTable([
['Name', 'Marks'],
['Sachin', 85],
['Amit', 60],
['Rohit', 75],
['Deepak', 50],
['Rahul', 55]
]);
var options = {
title: "Students Marks",
titleTextStyle: {
color: "red",
fontSize: 18,
bold: false,
}
};
var chart = new google.visualization.ColumnChart(my_chart);
chart.draw(data, options);
}
</script>
<style type="text/css">
#my_chart {
max-width: 900px;
height: 500px;
border: 1px solid #ccc;
}
</style>
<div id="my_chart"></div>
I need to place main title of chart (Students Marks) in the center of chart. I can’t see any option in official docs.
I tried a couple of options like titleTextPosition
and titlePosition
myself to test whether they work or not but they don’t.
Does anybody know how to do that?