gpt4 book ai didi

javascript - Google Charts LogScale 不工作

转载 作者:行者123 更新时间:2023-11-28 03:49:58 26 4
gpt4 key购买 nike

我正在使用 Google Charts 制作条形图,并尝试让图表在垂直轴上使用对数刻度,但由于某种原因它不起作用。我尝试过使用 logScale 和 scaleType 但它们都不起作用。

这是我的代码:

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 页面:https://jsfiddle.net/rm8vr1p8/

不太确定我做错了什么。我什至尝试过更改垂直轴的值,但它不起作用。我错过了什么?

最佳答案

Material 图表不支持多个选项,包括...
{hAxis,vAxis,hAxes.*,vAxes.*}.logScale

参见 --> Tracking Issue for Material Chart Feature Parity

<小时/>

Material = google.charts.Bar -- 包:['bar']

经典 = google.visualization.ColumnChart -- 包:['corechart']

<小时/>

有一个选项可以使经典图表看起来与 Material 相似...
主题:' Material

请参阅以下工作片段...

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>

关于javascript - Google Charts LogScale 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48087809/

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