我有3个输入字段和一个提交按钮,我只想在按下提交按钮时根据输入值显示条形图
我测试警报值,我可以得到它
这是html
$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
$ g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
$ ldd --version
ldd (GNU libc) 2.17
$ g++ a.cc
/tmp/cckbAM5c.o: In function `std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf()':
a.cc:(.text._ZNSt13basic_filebufIcSt11char_traitsIcEEC2Ev[_ZNSt13basic_filebufIcSt11char_traitsIcEEC5Ev]+0x46): undefined reference to `std::__basic_file<char>::__basic_file(int*)'
/tmp/cckbAM5c.o: In function `std::basic_filebuf<char, std::char_traits<char> >::seekoff(long long, std::_Ios_Seekdir, std::_Ios_Openmode)':
a.cc:(.text._ZNSt13basic_filebufIcSt11char_traitsIcEE7seekoffExSt12_Ios_SeekdirSt13_Ios_Openmode[_ZNSt13basic_filebufIcSt11char_traitsIcEE7seekoffExSt12_Ios_SeekdirSt13_Ios_Openmode]+0x1d8): undefined reference to `std::__basic_file<char>::seekoff(long long, std::_Ios_Seekdir)'
/tmp/cckbAM5c.o: In function `std::basic_filebuf<char, std::char_traits<char> >::_M_seek(long long, std::_Ios_Seekdir, __mbstate_t)':
a.cc:(.text._ZNSt13basic_filebufIcSt11char_traitsIcEE7_M_seekExSt12_Ios_Seekdir11__mbstate_t[_ZNSt13basic_filebufIcSt11char_traitsIcEE7_M_seekExSt12_Ios_Seekdir11__mbstate_t]+0x54): undefined reference to `std::__basic_file<char>::seekoff(long long, std::_Ios_Seekdir)'
collect2: error: ld returned 1 exit status
这是javascript
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Enter Value</label>
<input type="text" class="form-control" id="value1" name="value1" placeholder="Enter value">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Enter Value</label>
<input type="text" class="form-control" id="value2" name="value2" placeholder="Enter value">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Enter Value</label>
<input type="text" class="form-control" id="value3" name="value3" placeholder="Enter value">
</div>
<button type="submit" class="btn btn-primary" onclick="getVal()">Submit</button>
</form>
没有错误,但是也没有结果,我只想在数据:[0,10,2,20]上传递val1,val2,va3
答案 0 :(得分:1)
您需要将val1,val2和val3变量声明为函数外部的全局变量。当前val1 val2和val3仅在getVal()函数中可用。
一种更好的方法是创建一个数组,然后向其中添加值,就像这样:
var values = [];
values.push(document.getElementById('value1').value);
values.push(document.getElementById('value2').value);
values.push(document.getElementById('value3').value);
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: ['value1', 'value2', 'value3'],
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: values
}]
},
});