I have a chart that I would like to update whenever a form on the same page is submitted. The var chart = new Highcharts.Chart(options)
expression works fine by itself (it draws a chart). When I put it inside the callback function for the .click()
event, when I click the corresponding submit button, the updated plot flashes on the screen for a second and is then erased and replaced by the original plot.
I'm so close to doing what I need to, but I'm stumped by this. Thanks for your help.
Libraries:
<link type="text/css" href="css/cupertino/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/highcharts.js"></script>
Here is the Javascript:
<script>
$(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);
});
});
</script>
Here is the HTML body:
<body>
<form name="chartform" id="chartform">
<input type="submit" id="submit" /><br />
</form>
<div id="container" style="width: 100%; height: 800px"></div>
</body>
This is driving me nuts.