Google Charts Combo Chart not working with negative values dual y-axis
I'm trying to create a combo chart with bars and a line.
Unfortunately the bars start to render UNDERNEATH 0, looking like this:

I've already tried using series, vAxes etc., but I just don't know why it won't work. Even when I tried copying the Google Charts example (https://developers.google.com/chart/interactive/docs/gallery/combochart) it would still start rendering beneath 0.
Can someone help me out? Thank you very much!
This is my code right now:
https://jsfiddle.net/f73j2c4t/
function drawChart() {
var data = new google.visualization.DataTable({
cols:[
{id:"",label:"children(alle Produkte)",pattern:"",type:"string"},
{id:"",label:"2017","pattern":"",type:"number"},
{id:"",label:"2018","pattern":"",type:"number"}],
rows:[
{c:[{v:"Jan"},{v:2809071.1908},{v:457068.700399999}]},
{c:[{v:"Feb"},{v:7279392.48370001},{v:25487241.91010001}]},
{c:[{v:"Mar"},{v:15164932.691},{v:9540728.0996998}]},
{c:[{v:"Apr"},{v:178699480.161936},{v:123739963.468178}]},
{c:[{v:"Mai"},{v:43751922.3730972},{v:5883948.92010012}]},
{c:[{v:"Jun"},{v:40731561.1560001},{v:27896485.9954001}]},
{c:[{v:"Jul"},{v:14503044.8737},{v:7792566.08999991}]},
{c:[{v:"Aug"},{v:53713728.5248044},{v:41201792.2465999}]},
{c:[{v:"Sep"},{v:70934884.5715999},{v:55525900.4029}]},
{c:[{v:"Okt"},{v:12255561.1074006},{v:9710841.99769991}]},
{c:[{v:"Nov"},{v:6280620.07449995},{v:4282287.00650002}]},
{c:[{v:"Dez"},{v:4520620.07449995},{v:9267387.00650002}]}]
});
var formatter = new google.visualization.NumberFormat({
pattern: 'short'
});
var formatterP = new google.visualization.NumberFormat({
pattern: 'percent'
});
for (var i = 1; i < data.getNumberOfColumns(); i++) {
formatter.format(data, i);
}
var view = getDataView(data);
var colors = ["#E8E8E8", "#404040"];
var maxValCol = maxValue(view)
function maxValue(view) {
var maxA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(maxA < view.getColumnRange(i).max) {
maxA = view.getColumnRange(i).max;
}
}
return maxA;
}
var minValCol = minValue(view);
function minValue(view) {
var minA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(minA >= view.getColumnRange(i).min) {
minA = view.getColumnRange(i).min;
}
}
return minA;
}
function getDataView(dataTable) {
var dataView;
var viewColumns = ;
for (var i = 0; i < dataTable.getNumberOfColumns(); i++) {
addViewColumn(i);
}
function addViewColumn(index) {
viewColumns.push(index);
if (index == (dataTable.getNumberOfColumns() - 1)) {
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
});
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
role: "annotation"
});
}
}
dataView = new google.visualization.DataView(dataTable);
dataView.setColumns(viewColumns);
return dataView;
}
var options = {
annotations: {
alwaysOutside: true,
textStyle: {
fontSize: 10,
color: 'black',
}
},
height: 600,
width: 900,
colors: colors,
chartArea: {
height: "85%",
width: "100%",
left: "5%",
top: "5%"
},
vAxis: {
gridlines: {
color: 'transparent'
},
viewWindow: "maximized",
textPosition: "none",
},
legend: {
position: 'top',
alignment: "center",
maxLines: 3
},
bar: {
groupWidth: '70%'
},
seriesType: 'bars',
series: {
1: {
targetAxisIndex: 1
},
2: {
targetAxisIndex: 2,
type: 'line',
color: 'red',
}
},
};
var chart = new google.visualization.ComboChart(document.getElementById("absoluteValues"));
chart.draw(view, options);
javascript svg google-visualization googlevis
add a comment |
I'm trying to create a combo chart with bars and a line.
Unfortunately the bars start to render UNDERNEATH 0, looking like this:

I've already tried using series, vAxes etc., but I just don't know why it won't work. Even when I tried copying the Google Charts example (https://developers.google.com/chart/interactive/docs/gallery/combochart) it would still start rendering beneath 0.
Can someone help me out? Thank you very much!
This is my code right now:
https://jsfiddle.net/f73j2c4t/
function drawChart() {
var data = new google.visualization.DataTable({
cols:[
{id:"",label:"children(alle Produkte)",pattern:"",type:"string"},
{id:"",label:"2017","pattern":"",type:"number"},
{id:"",label:"2018","pattern":"",type:"number"}],
rows:[
{c:[{v:"Jan"},{v:2809071.1908},{v:457068.700399999}]},
{c:[{v:"Feb"},{v:7279392.48370001},{v:25487241.91010001}]},
{c:[{v:"Mar"},{v:15164932.691},{v:9540728.0996998}]},
{c:[{v:"Apr"},{v:178699480.161936},{v:123739963.468178}]},
{c:[{v:"Mai"},{v:43751922.3730972},{v:5883948.92010012}]},
{c:[{v:"Jun"},{v:40731561.1560001},{v:27896485.9954001}]},
{c:[{v:"Jul"},{v:14503044.8737},{v:7792566.08999991}]},
{c:[{v:"Aug"},{v:53713728.5248044},{v:41201792.2465999}]},
{c:[{v:"Sep"},{v:70934884.5715999},{v:55525900.4029}]},
{c:[{v:"Okt"},{v:12255561.1074006},{v:9710841.99769991}]},
{c:[{v:"Nov"},{v:6280620.07449995},{v:4282287.00650002}]},
{c:[{v:"Dez"},{v:4520620.07449995},{v:9267387.00650002}]}]
});
var formatter = new google.visualization.NumberFormat({
pattern: 'short'
});
var formatterP = new google.visualization.NumberFormat({
pattern: 'percent'
});
for (var i = 1; i < data.getNumberOfColumns(); i++) {
formatter.format(data, i);
}
var view = getDataView(data);
var colors = ["#E8E8E8", "#404040"];
var maxValCol = maxValue(view)
function maxValue(view) {
var maxA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(maxA < view.getColumnRange(i).max) {
maxA = view.getColumnRange(i).max;
}
}
return maxA;
}
var minValCol = minValue(view);
function minValue(view) {
var minA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(minA >= view.getColumnRange(i).min) {
minA = view.getColumnRange(i).min;
}
}
return minA;
}
function getDataView(dataTable) {
var dataView;
var viewColumns = ;
for (var i = 0; i < dataTable.getNumberOfColumns(); i++) {
addViewColumn(i);
}
function addViewColumn(index) {
viewColumns.push(index);
if (index == (dataTable.getNumberOfColumns() - 1)) {
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
});
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
role: "annotation"
});
}
}
dataView = new google.visualization.DataView(dataTable);
dataView.setColumns(viewColumns);
return dataView;
}
var options = {
annotations: {
alwaysOutside: true,
textStyle: {
fontSize: 10,
color: 'black',
}
},
height: 600,
width: 900,
colors: colors,
chartArea: {
height: "85%",
width: "100%",
left: "5%",
top: "5%"
},
vAxis: {
gridlines: {
color: 'transparent'
},
viewWindow: "maximized",
textPosition: "none",
},
legend: {
position: 'top',
alignment: "center",
maxLines: 3
},
bar: {
groupWidth: '70%'
},
seriesType: 'bars',
series: {
1: {
targetAxisIndex: 1
},
2: {
targetAxisIndex: 2,
type: 'line',
color: 'red',
}
},
};
var chart = new google.visualization.ComboChart(document.getElementById("absoluteValues"));
chart.draw(view, options);
javascript svg google-visualization googlevis
add a comment |
I'm trying to create a combo chart with bars and a line.
Unfortunately the bars start to render UNDERNEATH 0, looking like this:

I've already tried using series, vAxes etc., but I just don't know why it won't work. Even when I tried copying the Google Charts example (https://developers.google.com/chart/interactive/docs/gallery/combochart) it would still start rendering beneath 0.
Can someone help me out? Thank you very much!
This is my code right now:
https://jsfiddle.net/f73j2c4t/
function drawChart() {
var data = new google.visualization.DataTable({
cols:[
{id:"",label:"children(alle Produkte)",pattern:"",type:"string"},
{id:"",label:"2017","pattern":"",type:"number"},
{id:"",label:"2018","pattern":"",type:"number"}],
rows:[
{c:[{v:"Jan"},{v:2809071.1908},{v:457068.700399999}]},
{c:[{v:"Feb"},{v:7279392.48370001},{v:25487241.91010001}]},
{c:[{v:"Mar"},{v:15164932.691},{v:9540728.0996998}]},
{c:[{v:"Apr"},{v:178699480.161936},{v:123739963.468178}]},
{c:[{v:"Mai"},{v:43751922.3730972},{v:5883948.92010012}]},
{c:[{v:"Jun"},{v:40731561.1560001},{v:27896485.9954001}]},
{c:[{v:"Jul"},{v:14503044.8737},{v:7792566.08999991}]},
{c:[{v:"Aug"},{v:53713728.5248044},{v:41201792.2465999}]},
{c:[{v:"Sep"},{v:70934884.5715999},{v:55525900.4029}]},
{c:[{v:"Okt"},{v:12255561.1074006},{v:9710841.99769991}]},
{c:[{v:"Nov"},{v:6280620.07449995},{v:4282287.00650002}]},
{c:[{v:"Dez"},{v:4520620.07449995},{v:9267387.00650002}]}]
});
var formatter = new google.visualization.NumberFormat({
pattern: 'short'
});
var formatterP = new google.visualization.NumberFormat({
pattern: 'percent'
});
for (var i = 1; i < data.getNumberOfColumns(); i++) {
formatter.format(data, i);
}
var view = getDataView(data);
var colors = ["#E8E8E8", "#404040"];
var maxValCol = maxValue(view)
function maxValue(view) {
var maxA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(maxA < view.getColumnRange(i).max) {
maxA = view.getColumnRange(i).max;
}
}
return maxA;
}
var minValCol = minValue(view);
function minValue(view) {
var minA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(minA >= view.getColumnRange(i).min) {
minA = view.getColumnRange(i).min;
}
}
return minA;
}
function getDataView(dataTable) {
var dataView;
var viewColumns = ;
for (var i = 0; i < dataTable.getNumberOfColumns(); i++) {
addViewColumn(i);
}
function addViewColumn(index) {
viewColumns.push(index);
if (index == (dataTable.getNumberOfColumns() - 1)) {
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
});
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
role: "annotation"
});
}
}
dataView = new google.visualization.DataView(dataTable);
dataView.setColumns(viewColumns);
return dataView;
}
var options = {
annotations: {
alwaysOutside: true,
textStyle: {
fontSize: 10,
color: 'black',
}
},
height: 600,
width: 900,
colors: colors,
chartArea: {
height: "85%",
width: "100%",
left: "5%",
top: "5%"
},
vAxis: {
gridlines: {
color: 'transparent'
},
viewWindow: "maximized",
textPosition: "none",
},
legend: {
position: 'top',
alignment: "center",
maxLines: 3
},
bar: {
groupWidth: '70%'
},
seriesType: 'bars',
series: {
1: {
targetAxisIndex: 1
},
2: {
targetAxisIndex: 2,
type: 'line',
color: 'red',
}
},
};
var chart = new google.visualization.ComboChart(document.getElementById("absoluteValues"));
chart.draw(view, options);
javascript svg google-visualization googlevis
I'm trying to create a combo chart with bars and a line.
Unfortunately the bars start to render UNDERNEATH 0, looking like this:

I've already tried using series, vAxes etc., but I just don't know why it won't work. Even when I tried copying the Google Charts example (https://developers.google.com/chart/interactive/docs/gallery/combochart) it would still start rendering beneath 0.
Can someone help me out? Thank you very much!
This is my code right now:
https://jsfiddle.net/f73j2c4t/
function drawChart() {
var data = new google.visualization.DataTable({
cols:[
{id:"",label:"children(alle Produkte)",pattern:"",type:"string"},
{id:"",label:"2017","pattern":"",type:"number"},
{id:"",label:"2018","pattern":"",type:"number"}],
rows:[
{c:[{v:"Jan"},{v:2809071.1908},{v:457068.700399999}]},
{c:[{v:"Feb"},{v:7279392.48370001},{v:25487241.91010001}]},
{c:[{v:"Mar"},{v:15164932.691},{v:9540728.0996998}]},
{c:[{v:"Apr"},{v:178699480.161936},{v:123739963.468178}]},
{c:[{v:"Mai"},{v:43751922.3730972},{v:5883948.92010012}]},
{c:[{v:"Jun"},{v:40731561.1560001},{v:27896485.9954001}]},
{c:[{v:"Jul"},{v:14503044.8737},{v:7792566.08999991}]},
{c:[{v:"Aug"},{v:53713728.5248044},{v:41201792.2465999}]},
{c:[{v:"Sep"},{v:70934884.5715999},{v:55525900.4029}]},
{c:[{v:"Okt"},{v:12255561.1074006},{v:9710841.99769991}]},
{c:[{v:"Nov"},{v:6280620.07449995},{v:4282287.00650002}]},
{c:[{v:"Dez"},{v:4520620.07449995},{v:9267387.00650002}]}]
});
var formatter = new google.visualization.NumberFormat({
pattern: 'short'
});
var formatterP = new google.visualization.NumberFormat({
pattern: 'percent'
});
for (var i = 1; i < data.getNumberOfColumns(); i++) {
formatter.format(data, i);
}
var view = getDataView(data);
var colors = ["#E8E8E8", "#404040"];
var maxValCol = maxValue(view)
function maxValue(view) {
var maxA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(maxA < view.getColumnRange(i).max) {
maxA = view.getColumnRange(i).max;
}
}
return maxA;
}
var minValCol = minValue(view);
function minValue(view) {
var minA = 0;
for(var i = 0; i < view.getNumberOfColumns(); i++) {
if(minA >= view.getColumnRange(i).min) {
minA = view.getColumnRange(i).min;
}
}
return minA;
}
function getDataView(dataTable) {
var dataView;
var viewColumns = ;
for (var i = 0; i < dataTable.getNumberOfColumns(); i++) {
addViewColumn(i);
}
function addViewColumn(index) {
viewColumns.push(index);
if (index == (dataTable.getNumberOfColumns() - 1)) {
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
});
viewColumns.push({
calc: function(data, row) {
var value = 0;
value = (data.getValue(row, 2) - data.getValue(row, 1)) / data.getValue(row, 1);
return {
v: value,
f: formatterP.formatValue(value)
}
},
type: "number",
role: "annotation"
});
}
}
dataView = new google.visualization.DataView(dataTable);
dataView.setColumns(viewColumns);
return dataView;
}
var options = {
annotations: {
alwaysOutside: true,
textStyle: {
fontSize: 10,
color: 'black',
}
},
height: 600,
width: 900,
colors: colors,
chartArea: {
height: "85%",
width: "100%",
left: "5%",
top: "5%"
},
vAxis: {
gridlines: {
color: 'transparent'
},
viewWindow: "maximized",
textPosition: "none",
},
legend: {
position: 'top',
alignment: "center",
maxLines: 3
},
bar: {
groupWidth: '70%'
},
seriesType: 'bars',
series: {
1: {
targetAxisIndex: 1
},
2: {
targetAxisIndex: 2,
type: 'line',
color: 'red',
}
},
};
var chart = new google.visualization.ComboChart(document.getElementById("absoluteValues"));
chart.draw(view, options);
javascript svg google-visualization googlevis
javascript svg google-visualization googlevis
asked Nov 28 '18 at 16:47
RyuHayabusaRyuHayabusa
366
366
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53524317%2fgoogle-charts-combo-chart-not-working-with-negative-values-dual-y-axis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53524317%2fgoogle-charts-combo-chart-not-working-with-negative-values-dual-y-axis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown