用户更新标签后渲染Highcharts

Sea*_*ean 5 javascript highcharts

我正在尝试创建一个图表生成器.我有标题和图例位置的用户输入.我希望用户输入标题,然后单击关闭(模糊)图表以使用他们键入的内容进行更新.

问题是图表第一次渲染,但是我永远无法再次渲染char.以下是代码的快速摘要.

$('#legendlocation-select').blur(function updateChartLegend(){
console.log($('#legendlocation-select').val());
if($('#legendlocation-select').val()==='none'){
    chartData.legend.enabled = 'false';
}else{
    chartData.legend.enabled = 'true';
    chartData.legend.align = $('#legendlocation-select').val();
}
renderChart();
});
function renderChart(){
if(chart == undefined){
    console.log("First Draw");
    chart = new Highcharts.Chart(chartData);
}else{
    console.log("Redraw");
    chart.destroy();
    chart = new Highcharts.Chart(chartData);
    chart.redraw();
}
};
Run Code Online (Sandbox Code Playgroud)

图表第一次渲染,然后第二次只是一个空白区域.有任何想法吗?chartData是一个变量,其中包含正确呈现的所有选项.

这是一个JSFiddle,它显示了问题http://jsfiddle.net/zVjrb/3/

Sea*_*ean 10

想出了问题.详细信息请访问:http://highslide.com/forum/viewtopic.php?f = 12&t = 15255

基本上,Highcharts.charts函数清除原始选项对象中的系列数据.

这是我的工作代码:

var chart;
var chartData = { /* you chart data goes here */ };
$('#legendlocation-select').blur(function updateChartLegend(){
  console.log($('#legendlocation-select').val());
  if($('#legendlocation-select').val()==='none'){
    chart.options.legend.enabled = false;
  }else{
    chart.options.legend.enabled = true;
    chart.options.legend.align = $('#legendlocation-select').val();
  }
  renderChart();
});

function renderChart(){
  //console.log(chartData);
  if(chart == undefined){
    console.log("First Draw");
    chart = new Highcharts.Chart(chartData);
  }else{
    console.log("Redraw");
    chart.options.chart.animation = false;
    chart = new Highcharts.Chart(chart.options);
    chart.render();
  }
};
Run Code Online (Sandbox Code Playgroud)

  • 在将高图加载到jquery-ui对话框时我遇到了类似的问题 - 我最后通过清除对话框div来解决它,特别是调用$('.highcharts-container').removeClass().希望这可以帮助别人并节省他们一小时左右它浪费在我身上. (2认同)