使用jquery中的click()事件从表单更新Highchart

我有一个图表,我想在同一页面上提交表单时更新。 var chart = new Highcharts.Chart(options)表达式可以正常工作(它绘制图表)。 当我把它放在.click()事件的回调函数中时,当我单击相应的提交按钮时,更新的图表会在屏幕上闪烁一秒钟然后被删除并被原始图表替换。

我非常接近于做我需要做的事情,但我很难过。 谢谢你的帮助。

图书馆:

     

这是Javascript:

  $(function() { $("#lines").val(),colors: $("#colors").val(),}, var options = { chart : { renderTo : 'container', defaultSeriesType: 'line', zoomType: 'xy' }, title : { text : 'Foo' }, xAxis: { title: { text: 'x label' } }, yAxis: { title: { text: 'y label' } }, series : {} } var chart = new Highcharts.Chart(options); $( "#submit" ).click(function() { options.series = [{"name": 10402, "color": "rgba(255,139,0,0.5)", "data": [[ 146,55.8 ],[150,60.9]]},{"name": 10403, "color": "rgba(255,255,0,0.5)", "data": [[ 130,25.8 ],[150,54.9]]}]; var chart = new Highcharts.Chart(options); }); });  

这是HTML正文:

  

这让我疯了。

这对我来说很好:

 var chart; $(document).ready(function() { options ={ chart: { renderTo: 'container', defaultSeriesType: 'line', zoomType: 'xy' }, title : { text : 'Foo' }, xAxis: { title: { text: 'x label' } }, yAxis: { title: { text: 'y label' } }, series: {} }; chart = new Highcharts.Chart(options); series3 = [{"name": 10402, "color": "rgba(255,139,0,0.5)", data: [[ 146,55.8 ],[150,60.9]]},{"name": 10403, "color": "rgba(255,255,0,0.5)", "data": [[ 130,25.8 ],[150,54.9]]}]; series2 = [{ name: '1042', color: "rgba(255,139,0,0.5)", data: [[ 146,55.8 ],[150,60.9]] }, { name: '10403', color: "rgba(255,255,0,0.5)", data: [[ 130,25.8 ],[150,54.9]] }]; $( "#chartform" ).submit(function() { options.series = series3; var chart = new Highcharts.Chart(options); return false; }); }); 

编辑:我认为问题是你提交表格。 返回false并使用提交处理程序而不是单击。 你可以查看: http : //jsfiddle.net/bCFHL/157/