I’m trying to style and add another 2 x’axis to a Google area chart (a and b in the image). For example, the a axis should be set to 900 and b: 700.
Also trying to extend the chart to the full width of the containing div (960px) but my solution seems to do nothing.

This is the desired effect.
Current js
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['November', 1000, 400],
['December', 1170, 460],
['January', 660, 1120],
['February', 690, 1120],
['March', 780, 1120],
['April', 820, 1120],
['May', 660, 1120],
['June', 1030, 540]
]);
var options = {
title: '',
backgroundColor: 'none',
width:'960',
legend: {position: 'none'},
hAxis: {title: 'Year', titleTextStyle: {color: 'grey'},
}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
To get the chart width right, add a
chartAreadefinition to youroptionsobject. ThechartAreasettings are listed in theAreaChartdocumentation under “Configuration Options”:Demo: http://jsfiddle.net/2H7sp/
You’ll need to play with the numbers a little bit.
chartArearefers to the graphical portion of the chart, excluding the axes, title, and legend. So you need to add padding to your values in order to leave room.Edit: To get the horizontal lines, you’ll need to add two additional series with values of 900 and 700 for each row in the respective columns:
To get the colors right, specify a definition for the
seriesoption that sets the area invisible and the line color black for the two new series.This is close, but the lines will be solid instead of dashed, and there will be no labels. You can get these effects by adding columns with roles to your data table. You’ll not be able to use
.arrayToDataTable()for this, but instead will need to use the more verbose syntax:For dashed lines add a certainty role column following each of your “a” and “b” columns:
To get the “a” and “b” labels add a annotation role columns following each of your certainty columns:
The certainty column values should all be
false. The annotation column values should all be null except for the last row where you want the label to appear. The annotation aligns above the data point instead of to the right where you want it, but that’s as good as you can get.Your data rows with the new columns added will look like this:
And, here’s the end result: http://jsfiddle.net/2H7sp/2/