gpt4 book ai didi

jquery - 谷歌柱形图中的Y轴值以相反顺序显示

转载 作者:行者123 更新时间:2023-12-01 08:45:02 27 4
gpt4 key购买 nike

Google 柱形图中的 Y 轴值以相反顺序显示。请看一下我得到的结果。

enter image description here

我的代码是:

HTML

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<div class="col-sm-6" id="job_chart" style="width: 800px; height: 500px;"></div>

jquery

$.post("/emp_action_ajax.html",{'ajaxOp':'loadJobChart'},function(data){
var data_array = $.parseJSON(data);
var dataarray = [["Date", "Job"]];
for (var i = 0; i < data_array.length; i++) {
var sub = [data_array[i].date, data_array[i].jcount];
dataarray.push(sub);
}
drawStuff(dataarray);
});

google.load("visualization", "1.1", {packages: ['corechart', 'bar']});
function drawStuff(dataArray) {
var data = new google.visualization.arrayToDataTable(dataArray);

var options = {
width: 400,
legend: { position: 'none' },
chart: {
title: 'Year and month wise job count',
subtitle: '' },
axes: {
x: {
0: { side: 'bottom', label: 'Month-Year'} // Bottom x-axis.
},
/*y: {
0: { side: 'bottom', label: 'Job', direction: '-1'}
}*/
},
/*vAxis: {
title: 'Job',
direction: '1'
},*/
bar: { groupWidth: "50%" }
};

var chart = new google.charts.Bar(document.getElementById('job_chart'));
chart.draw(data, google.charts.Bar.convertOptions(options));
};

我尝试过的

y: {
0: { side: 'bottom', label: 'Job', direction: '-1'}
}

并且

vAxis: {
title: 'Job',
direction: '1' //-1
}

UPADTE

我提醒 drawStuff(dataArray) 函数内的 dataArray 并获取

enter image description here

最佳答案

这是因为您的 data_array[i].jcount 值被视为字符串,以使其可以使用 parseInt()

for (var i = 0; i < data_array.length; i++) {
var sub = [data_array[i].date, parseInt(data_array[i].jcount)];
dataarray.push(sub);
}

非工作片段,

var dataArray = [
["Date", "Job"],
['2017-1', '5'],
['2017-4', '2']
];
google.load("visualization", "1.1", {
packages: ['corechart', 'bar']
});
google.setOnLoadCallback(drawStuff);

function drawStuff() {
var data = new google.visualization.arrayToDataTable(dataArray);

var options = {
width: 400,
legend: {
position: 'none'
},
chart: {
title: 'Year and month wise job count',
subtitle: ''
},
axes: {
x: {
0: {
side: 'bottom',
label: 'Month-Year'
} // Bottom x-axis.
}
},
vAxis: {
title: 'Job',
direction: '-1'
},
bar: {
groupWidth: "50%"
}
};

var chart = new google.charts.Bar(document.getElementById('job_chart'));
chart.draw(data, google.charts.Bar.convertOptions(options));
};
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<div class="col-sm-6" id="job_chart" style="width: 800px; height: 500px;"></div>

工作片段,

var dataArray = [
["Date", "Job"],
['2017-1', 5],
['2017-4', 2]
];
google.load("visualization", "1.1", {
packages: ['corechart', 'bar']
});
google.setOnLoadCallback(drawStuff);

function drawStuff() {
var data = new google.visualization.arrayToDataTable(dataArray);

var options = {
width: 400,
legend: {
position: 'none'
},
chart: {
title: 'Year and month wise job count',
subtitle: ''
},
axes: {
x: {
0: {
side: 'bottom',
label: 'Month-Year'
} // Bottom x-axis.
}
},
vAxis: {
title: 'Job',
direction: '-1'
},
bar: {
groupWidth: "50%"
}
};

var chart = new google.charts.Bar(document.getElementById('job_chart'));
chart.draw(data, google.charts.Bar.convertOptions(options));
};
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<div class="col-sm-6" id="job_chart" style="width: 800px; height: 500px;"></div>

关于jquery - 谷歌柱形图中的Y轴值以相反顺序显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43514518/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com