gpt4 book ai didi

javascript - Google Graphs 轴顺序

转载 作者:可可西里 更新时间:2023-11-01 13:42:41 26 4
gpt4 key购买 nike

我有一个简单的输入表单,用户可以使用它通过下拉菜单/选择器输入数据。有 10 个问题,每个问题的评分都是 10 分。

然后,此数据会填充同一页面上的 Google 图。

数据很好地填充了图表,但轴本身变得无序。所以 2 可能在顶部,10 在中间,依此类推。我不知道为什么轴会像这样“断裂”。

请注意,我对 Java 和一点 HTML 的经验很少,这只是我想学习但无法在任何地方找到答案,或者至少,当我看到答案时无法识别!

有人可以帮忙吗?

<!doctype HTML>
<html`enter code here` lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>

</title>
<head>
<style>



</style>
</head>
<body>


<h1>REPORT CARD</h1>

<br>

<form role="form" id="price" name="price">
<p><b>The brand excels</b></p>

<select class="custom-select" style="width:100pt; height:30pt; font-size:15px; color:grey; float:right;" id="DB" onchange="drawChart()">
<option id="itemprice" color="green" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>
<br>
<p>Relevance:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px; color:grey;float:right" id="RLV" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>
<p>Pricing related to Value:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey ;float:right" id="PRV" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Positioning:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px; color:grey;float:right" id="PSN" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Consistency:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="CNS" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Brand Portfolio:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="BP" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Marketing Activities:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="MA" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Brand Meaning:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="BM" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Support of the Brand:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="SOB" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>


<p>Brand Equity:</p>
<select class="custom-select" style="width:100pt; height:30pt; text-align: center; font-size:15px;color:grey;float:right " id="BE" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>


</form>

<br> </br><br> </br>

</body>

<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
var data = google.visualization.arrayToDataTable([
['Metrics','Delivering Benefits','Relevance', 'Pricing related to Value','Positioning','Consistency', 'Brand Portfolio','Marketing Activities','Brand Meaning', 'Support of the Brand', 'Brand Equity'],
[" ",
value=document.getElementById("DB").value,
value=document.getElementById("RLV").value,
value=document.getElementById("PRV").value,
value=document.getElementById("PSN").value,
value=document.getElementById("CNS").value,
value=document.getElementById("BP").value,
value=document.getElementById("MA").value,
value=document.getElementById("BM").value,
value=document.getElementById("SOB").value,
value=document.getElementById("BE").value,],

]);


var options = {


chart: {
title: 'XYZ',
subtitle: '',
},
bars: 'vertical' // Required for Material Bar Charts.
};

var chart = new google.charts.Bar(document.getElementById('barchart_material'));

chart.draw(data, google.charts.Bar.convertOptions(options));
}
</script>
</head>
<body>
<div id="barchart_material" style="width: 1000px; height: 500px;"></div>
</body>



</html>

最佳答案

y 轴上的数据乱序,因为图表数据中使用了 string 值,
而不是 number

要更正,您可以使用 parseInt 将字符串转换为数字。

          [" ", 
parseInt(document.getElementById("DB").value),
parseInt(document.getElementById("RLV").value),
parseInt(document.getElementById("PRV").value),
parseInt(document.getElementById("PSN").value),
parseInt(document.getElementById("CNS").value),
parseInt(document.getElementById("BP").value),
parseInt(document.getElementById("MA").value),
parseInt(document.getElementById("BM").value),
parseInt(document.getElementById("SOB").value),
parseInt(document.getElementById("BE").value)],

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

<!doctype HTML>
<html`enter code here` lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>

</title>
<head>
<style>



</style>
</head>
<body>


<h1>REPORT CARD</h1>

<br>

<form role="form" id="price" name="price">
<p><b>The brand excels</b></p>

<select class="custom-select" style="width:100pt; height:30pt; font-size:15px; color:grey; float:right;" id="DB" onchange="drawChart()">
<option id="itemprice" color="green" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>
<br>
<p>Relevance:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px; color:grey;float:right" id="RLV" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>
<p>Pricing related to Value:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey ;float:right" id="PRV" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Positioning:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px; color:grey;float:right" id="PSN" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Consistency:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="CNS" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Brand Portfolio:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="BP" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Marketing Activities:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="MA" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Brand Meaning:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="BM" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>

<p>Support of the Brand:</p>
<select class="custom-select" style="width:100pt; height:30pt; font-size:15px;color:grey;float:right " id="SOB" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>
<br>


<p>Brand Equity:</p>
<select class="custom-select" style="width:100pt; height:30pt; text-align: center; font-size:15px;color:grey;float:right " id="BE" onchange="drawChart()">
<option id="itemprice" value="">Please choose</placeholder>
<option id="itemprice" value="1" >1 </option>
<option id="itemprice" value="2">2</option>
<option id="itemprice" value="3">3</option>
<option id="itemprice" value="4">4</option>
<option id="itemprice" value="5">5</option>
<option id="itemprice" value="6">6</option>
<option id="itemprice" value="7">7</option>
<option id="itemprice" value="8">8</option>
<option id="itemprice" value="9">9</option>
<option id="itemprice" value="10">10</option>
</select>

</p>


</form>

<br> </br><br> </br>

</body>

<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
var data = google.visualization.arrayToDataTable([
['Metrics','Delivering Benefits','Relevance', 'Pricing related to Value','Positioning','Consistency', 'Brand Portfolio','Marketing Activities','Brand Meaning', 'Support of the Brand', 'Brand Equity'],
[" ",
parseInt(document.getElementById("DB").value),
parseInt(value=document.getElementById("RLV").value),
parseInt(value=document.getElementById("PRV").value),
parseInt(value=document.getElementById("PSN").value),
parseInt(value=document.getElementById("CNS").value),
parseInt(value=document.getElementById("BP").value),
parseInt(value=document.getElementById("MA").value),
parseInt(value=document.getElementById("BM").value),
parseInt(value=document.getElementById("SOB").value),
parseInt(value=document.getElementById("BE").value)],

]);


var options = {


chart: {
title: 'XYZ',
subtitle: '',
},
bars: 'vertical' // Required for Material Bar Charts.
};

var chart = new google.charts.Bar(document.getElementById('barchart_material'));

chart.draw(data, google.charts.Bar.convertOptions(options));
}
</script>
</head>
<body>
<div id="barchart_material" style="width: 1000px; height: 500px;"></div>
</body>



</html>

注意:不需要value=...

关于javascript - Google Graphs 轴顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52580166/

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