2014-01-17 42 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);