Secondary Axis to the google chart

580 views
Skip to first unread message

Tong Sun

unread,
May 5, 2014, 10:59:09 AM5/5/14
to google-visua...@googlegroups.com
Hi, 

Is it possible to add a secondary axis to a google chart?

Basically I'm trying to do this, http://jeffprom.com/2012/09/05/add-excel-chart-percentage-differences/, i.e, adding a second series of entirely different data range as line chart to an existing bar chart. Is it possible with google chart?

Thanks


Andrew Gallant

unread,
May 5, 2014, 11:23:43 AM5/5/14
to google-visua...@googlegroups.com
Yes, you can do that.  If you want to mix columns and lines, use a ComboChart.  In the chart options, specify the series.<series index>.targetAxisIndex option to target the left (axis 0) or right (axis 1) axes.  You can set the options for the axes by using the vAxes.<axis index> options.  These take the exact same sub-options as the vAxis option.

series: {
    0: {
        type: 'bars',
        targetAxisIndex: 0
    },
    1: {
        type: 'line',
        targetAxisIndex: 1
    }
},
vAxes: {
    0: {
        format: '#,###'
    },
    1: {
        format: '#%'
    }
}

Tong Sun

unread,
May 5, 2014, 1:57:42 PM5/5/14
to google-visua...@googlegroups.com
Thanks a lot Andrew.

What's the syntax to specify more series to use the secondary axis, do I have to specify them one by one, or I can do something like this:

series: {
    0,2,4: {

        type: 'bars',
        targetAxisIndex: 0
    },
    1,3,5: {

        type: 'line',
        targetAxisIndex: 1
    }
}

Thanks



--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/KU8-KtygxVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Andrew Gallant

unread,
May 5, 2014, 9:58:14 PM5/5/14
to google-visua...@googlegroups.com
You have to specify each series individually.  The numbers are javascript object parameters (like "type" and "targetAxisIndex" are object parameters), so you can't play tricks with them like that.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages