admin管理员组文章数量:1405193
Most charting gauges seem to only support a starting value (min) of 0.
We have a need for the starting value to be the max and end value to be min so that the needle is maxed out for the lowest value.
E.g. Think of the gauge as a ranking of top 20 developers the example below you were rated number 3.
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Rank', 20 - 3]
]);
var options = {
width: 250,
height: 250,
redFrom: 0,
redTo: 10,
yellowFrom: 10,
yellowTo: 15,
greenFrom: 15,
greenTo: 20,
minorTicks: 20,
max: 20,
min: 0,
majorTicks: ['20', '1']
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
}
<script type="text/javascript" src="={'modules':[{'name':'visualization','version':'1.1','packages':['gauge']}]}"></script>
<div id="chart_div" style="width: 400px; height: 400px;"></div>
Most charting gauges seem to only support a starting value (min) of 0.
We have a need for the starting value to be the max and end value to be min so that the needle is maxed out for the lowest value.
E.g. Think of the gauge as a ranking of top 20 developers the example below you were rated number 3.
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Rank', 20 - 3]
]);
var options = {
width: 250,
height: 250,
redFrom: 0,
redTo: 10,
yellowFrom: 10,
yellowTo: 15,
greenFrom: 15,
greenTo: 20,
minorTicks: 20,
max: 20,
min: 0,
majorTicks: ['20', '1']
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.google./jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['gauge']}]}"></script>
<div id="chart_div" style="width: 400px; height: 400px;"></div>
But the problem is since the gauge really does not support this I kinda hacked it to work they way I wanted. Everything works great except for 1 thing. You will notice the value says 17 at the bottom because of this hack:
['Rank', 20-3]
Can I write a line of jquery to replace this value in the svg results?
Any help would be appreciated.
Share Improve this question edited Oct 19, 2015 at 3:21 Tushar 87.3k21 gold badges163 silver badges181 bronze badges asked Oct 19, 2015 at 3:17 CarntelCarntel 4291 gold badge4 silver badges16 bronze badges1 Answer
Reset to default 2Change options and data:
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Rank', 3]
]);
var options = {
width: 250,
height: 250,
redFrom: 20,
redTo: 10,
yellowFrom: 10,
yellowTo: 5,
greenFrom: 5,
greenTo: 0,
minorTicks: 20,
max: 0,
min: 20,
majorTicks: ['20', '1']
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
}
https://jsfiddle/mblenton/xasppevj/
本文标签: javascriptGoogle Charts GaugeStack Overflow
版权声明:本文标题:javascript - Google Charts Gauge - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744872665a2629723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论