[英]Highcharts oncahnge event It works on the first try but not on the second try
I'm coding a graph that expresses the day-by-day graph.我正在编写一个表示每日图表的图表。
I want to change the graph through select tag.我想通过选择标签更改图表。
So, i use javascript onchange.所以,我使用 javascript onchange。
But, It works on the first try but not on the second try.但是,它在第一次尝试时有效,但在第二次尝试时无效。
https://jsfiddle.net/7eqn02yu/ https://jsfiddle.net/7eqn02yu/
This is my code JS fiddle.这是我的代码 JS 小提琴。 And this is code.这是代码。 How does the function run every time?函数如何每次运行?
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script> <button id="export-pdf">Export PDF</button> <div id="map"></div> <script src="./index.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <select id="mySelect"> <option value="0">mon</option> <option value="1">tues</option> <option value="2">wed</option> <option value="3">thr</option> </select> <div id="container" style="height: 400px; width: 500px"></div> <script type="text/javascript"> const chart = Highcharts.chart('container', { plotOptions: { series: { point: { } } }, series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }] }); document.getElementById("mySelect").onchange = function () { myFunction() }; function myFunction() { var x = document.getElementById("mySelect").value; if (x = 0) { const series = chart.series[0]; if (series.data.length) { chart.series[0].remove(); } chart.addSeries({ data: [100, 100, 100, 100, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5] }); } else if (x = 1) { const series = chart.series[0]; if (series.data.length) { chart.series[0].remove(); } chart.addSeries({ data: [200, 200, 200, 200, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5] }); } else if (x = 2) { const series = chart.series[0]; if (series.data.length) { chart.series[0].remove(); } chart.addSeries({ data: [200, 200, 200, 200] }); } } </script>
Instead of if (x=0) use if (x===0)
and for the rest of the else if's代替if (x=0) use if (x===0)
和 else if 的其余部分
as following:如下:
if (x = 0){ // Use if (x === 0){
...
else if (x = 1){ // use else if (x===1)
const series = chart.series[0];
...
}else if (x = 2){// use else if (x===2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.