Anjana Choudhary Anjana Choudhary - 2 years ago 102
Ajax Question

how to draw high chart using function?

$(document).ready(function() {
Highcharts.setOptions(Highcharts.theme);
$('#div-chart').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Average Purchase',
align: 'center'
},
subtitle: {
text: ' '
},
xAxis: {
categories: <?php echo json_encode($result['day']) ?>,
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Amount (Millions)'
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Purchase',
data: <?php echo json_encode($result['amount']) ?>
}]
});
});


In
$(document).ready(function(){});
I'm defining the properties how my chart is drawn, what comes to x-axis and y-axis and properties of it. But, now I want to build a function in which I pass argument whether I want to draw high chart or canvas and then that function draw chart. How to start this? Can anyone help?

Answer Source

I am not sure this is you want!. And you cannot make common function because you cannot change the keywords like Highcharts dynamically. so it's better to write a separate function for both and call whatever you want.

$(document).ready(function() {
    drawChart(chart_type, args...);
});

function drawChart(chart_type, args....){
    if (type === 'highchart') {
        drawHighChart(args);
    } else if (type === 'canvas'){
        drawCanvas(args);
    }
}

function drawHighChart(args){

}

function drawHighChart(args){

}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download