Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google visualization stacked area chart: Add total to tooltip

I'm using the google visualization api to create a stacked area chart. When a user hovers over a point inside the chart, I want it to show the total added sum of the points at that location, as well as the values of those points.

The second point, I can easily achieve by specifying the option focusTarget: 'category'. I would like to have, in a similar look-and-feel, an extra line in the tooltip for total.

I tried achieving this by adding an extra column named Total which would have a value of 0, but a tooltip equal to the sum. This however adds an empty line to both the legend and the chart itsself, which isn't visually appealing.

This feels to me as something that should be available out of the box, but I can't find any sollutions to this problem.

If anyone knows of a good way to fix this, please answer. Thanks in advance.

like image 659
Kippie Avatar asked Sep 09 '13 13:09

Kippie


People also ask

How do I customize my Google bar graph?

Customize a bar chartChoose an option: Chart style: Change how the chart looks. Chart & axis titles: Edit or format title text. Series: Change bar colors, axis location, or add error bars, data labels, or trendline.

How do you read a stacked area chart?

In the stacked area chart, lines are plotted one at a time, with the height of the most recently-plotted group serving as a moving baseline. As such, the fully-stacked height of the topmost line will correspond to the total when summing across all groups.

What is the main difference between area and column charts?

Area Charts have axes with continuous scales that will show the dates in the right intervals; column charts don't. In this case, an area chart is also a better choice than a line chart. That's because the differences between the values are big enough, so the trend can be seen well enough on an area chart.


1 Answers

Since you already have the total column, you can make the line disappear and remove the total from the legend by using the series option:

series: {
    <series index of the total>: {
         lineWidth: 0,
         pointSize: 0,
         visibleInlegend: false
    }
}

I would recommend making the total column your first data series (column index 1, series index 0), as that puts it at the bottom of the chart where it won't interfere with your other series.

like image 184
asgallant Avatar answered Sep 19 '22 14:09

asgallant