[英]Google Charts LogScale not working
I'm using Google Charts to make a bar graph and I'm trying to get the graph to use a logscale on the vertical axis but it's not working for some reason. 我正在使用Google Charts制作条形图,并且试图使该图在垂直轴上使用对数刻度,但由于某些原因它无法正常工作。 I've tried using logScale and scaleType but neither of them work.
我试过使用logScale和scaleType,但是它们都不起作用。
Here's my code: 这是我的代码:
google.charts.load('current', {
'packages': ['bar']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Vendor', 'Nootropics Depot', 'Pure Nootropics', 'Peak Nootropics', 'Absorb Health'],
['ALCAR', 0.07, 0.20, 0.12, 0.24],
['Agmatine', 0.13, null, 0.23, null],
['Coluracetam', 13.80, 27.49, null, null],
['Oxiracetam', 0.47, 0.37, 0.58, 0.63],
['Phenibut', 0.22, null, 0.59, 0.60],
['Phenylpiracetam', 2.83, 3.33, 5.30, null],
['Polygala', 0.42, null, null, null],
['Pramiracetam', 1.67, 2.22, 1.60, 2.60],
['PRL-8-53', 23.99, null, null, null],
['Rhodiola Rosea 3% Rosavins', 0.23, 0.60, 0.32, 0.26],
]);
var formatter = new google.visualization.NumberFormat({
suffix: 'tablets',
negativeColor: 'red',
negativeParens: true
});
formatter.format(data, 0);
var formatter = new google.visualization.NumberFormat({
prefix: '$',
negativeColor: 'red',
negativeParens: true
});
formatter.format(data, 1);
formatter.format(data, 2);
formatter.format(data, 3);
formatter.format(data, 4);
var options = {
chart: {
title: 'Cheapest price per gram',
},
bars: 'vertical', // Required for Material Bar Charts.
hAxis: {
format: 'decimal',
},
vAxis: {
title: 'Price',
format: '$#',
minValue: 0.1,
logScale: true,
},
height: 400,
colors: ['#1b9e77', '#d95f02', '#7570b3']
};
var chart = new google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
JSFiddle page: https://jsfiddle.net/rm8vr1p8/ JSFiddle页面: https ://jsfiddle.net/rm8vr1p8/
Not really sure what I'm doing wrong. 不太确定我在做什么错。 I've even tried changing the values of the vertical axis but it just isn't working.
我什至尝试更改垂直轴的值,但它不起作用。 What am I missing?
我想念什么?
there are several options that are not supported by Material charts, including... 材质图表不支持几个选项,包括...
{hAxis,vAxis,hAxes.*,vAxes.*}.logScale
see --> Tracking Issue for Material Chart Feature Parity 请参阅-> 物料图特征奇偶校验的跟踪问题
Material = google.charts.Bar
-- packages: ['bar']
材质 =
google.charts.Bar
packages: ['bar']
Classic = google.visualization.ColumnChart
-- packages: ['corechart']
经典 =
google.visualization.ColumnChart
packages: ['corechart']
there is an option for Classic charts to look similar to Material ... 经典图表有一个选项类似于 材料 ...
theme: 'material
see following working snippet... 请参阅以下工作片段...
google.charts.load('current', { packages: ['corechart'] }).then(function () { var data = google.visualization.arrayToDataTable([ ['Vendor', 'Nootropics Depot', 'Pure Nootropics', 'Peak Nootropics', 'Absorb Health'], ['ALCAR', 0.07, 0.20, 0.12, 0.24], ['Agmatine', 0.13, null, 0.23, null], ['Coluracetam', 13.80, 27.49, null, null], ['Oxiracetam', 0.47, 0.37, 0.58, 0.63], ['Phenibut', 0.22, null, 0.59, 0.60], ['Phenylpiracetam', 2.83, 3.33, 5.30, null], ['Polygala', 0.42, null, null, null], ['Pramiracetam', 1.67, 2.22, 1.60, 2.60], ['PRL-8-53', 23.99, null, null, null], ['Rhodiola Rosea 3% Rosavins', 0.23, 0.60, 0.32, 0.26], ]); var formatter = new google.visualization.NumberFormat({ suffix: 'tablets', negativeColor: 'red', negativeParens: true }); formatter.format(data, 0); var formatter = new google.visualization.NumberFormat({ prefix: '$', negativeColor: 'red', negativeParens: true }); formatter.format(data, 1); formatter.format(data, 2); formatter.format(data, 3); formatter.format(data, 4); var options = { theme: 'material', title: 'Cheapest price per gram', hAxis: { format: 'decimal' }, vAxis: { title: 'Price', format: '$#', minValue: 0.1, logScale: true }, height: 400, colors: ['#1b9e77', '#d95f02', '#7570b3'] }; var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data, options); });
<script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.