Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to replace PHP array $os_array with JavaScript variable to send with different values. Like as var x =<?php echo $os_array; ?>; drawcharts($x); when alert var x result will be ['Internet Explorer 7',1],['Internet Explorer 8',1],['Outlook 2007',2]

var x="<?php echo $os_array;?>";
drawcharts(x);
function drawcharts(x){
    $('#_shared_graphs').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            backgroundColor: '#f1f1f1'
        },
        title: {
            text: 'OS'
        },
        tooltip: {
            pointFormat: '{point.y} Using <b>{point.name}'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
                type: 'pie',
                name: 'Sent Messag stat',
                data: [x]
            }]
    });
}
share|improve this question
3  
Where is the title? Where is the question? –  Karlen Kishmiryan Apr 29 at 10:12
    
i want to replace php array $os_array with js variable to send with differnt values . like as var x =<?php echo $os_array; ?>; drawcharts($x); –  Mohamed Badr Apr 29 at 10:18

1 Answer 1

well just define your js fkt:

function drawcharts(x) {

 $('#_shared_graphs').highcharts({
  ...

series: [{
        ...
        data: x
    }]
 });
}

then

 var x =<?php echo json_encode($os_array); ?>; 
 drawcharts(x);

 // reassign x
 x = [ .... ];
 drawcharts(x);
share|improve this answer
    
it not draw , my code like as above code kindly check it –  Mohamed Badr Apr 29 at 10:44
    
$os_array= ['Internet Explorer 7',1],['Internet Explorer 8',1],['Outlook 2007',2]; –  Mohamed Badr Apr 29 at 10:49
    
ok i have a solution : var x ="[<?php echo $os_array;?>]"; x= eval(x); drawcharts(x); –  Mohamed Badr Apr 29 at 10:54
    
edited with using json_encode to create a propper js-array output –  fast Apr 29 at 11:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.