2014-01-17 41 views
0

我需要新的功能添加HighCharts - 添加新的动态功能

function(chart) { // on complete 

chart.renderer.path(['M', 300, 0, 'L', 300, 300]) 
    .attr({ 
     'stroke-width': 2, 
     stroke: 'red' 
    }) 
    .add(); 

chart.renderer.path(['M', 0, 150, 'L', 500, 150]) 
    .attr({ 
     'stroke-width': 2, 
     stroke: 'red' 
    }) 
    .add(); 

} 

OR

function(chart) { // on complete 
    var textX = chart.plotLeft + (chart.plotWidth * 0.5); 
    var textY = chart.plotTop + (chart.plotHeight * 0.5); 

    var span = '<span id="pieChartInfoText" style="position:absolute; text-align:center;">'; 
    span += '<span style="font-size: 32px">Upper</span><br>'; 
    span += '<span style="font-size: 16px">Lower</span>'; 
    span += '</span>'; 

    $("#addText").append(span); 
    span = $('#pieChartInfoText'); 
    span.css('left', textX + (span.width() * -0.5)); 
    span.css('top', textY + (span.height() * -0.5)); 
} 

我现有图表。这些功能是动态的。他们每次更新数据库时都会更改。我怎样才能做到这一点?。

我需要一个代码,这个功能追加到现有的高图表

回答

0

谢谢你们的回应。 我得到了答案。

//Eg code : 

var customFunc = function(chart , code) { 
return new Function("chart" , code)(chart); 
} 

// load chart new Function to chart 
function getChartFunction(chartObj) { 

if(newFunctionCode){ 

    customFunc(chartObj , newFunctionCode); 
    } 
} 

// new newFunctionCode eg: 
chart.renderer.path(['M', 300, 0, 'L', 300, 300]) .attr({ 'stroke-width': 2, stroke: 'red' }).add(); 
chart.renderer.path(['M', 0, 150, 'L', 500, 150]) .attr({ 'stroke-width': 2, stroke: 'red' }).add(); 
0

你可以把脚本单独的文件,然后使用getScript,每当你想LAOD它。

$.getScript("jscodefilr.js", function(){ 
alert("Running jscodefilr.js"); 
}); 
0

你只是想盯回电?如果是这样你不需要使用匿名函数,试试这个:

function myCallback(chart) { 
    // code 
} 

var options = { 
    chart: { 
     .. 
    }, 

    // more options 

    series: [{ 
     data: [ .. ] 
    }] 
} 

$("#container").highcharts(options, callback);