简体   繁体   中英

PHP Variable in JavaScript Tag

I need a help with using PHP variable in JavaScript situation. I want to use PHP variable in a morris chart such as,

var area = new Morris.Area({
                    element: 'revenue-chart',
                    resize: true,
                    data: [
                        {y: '6D', fab: 20004, qc: 0},
                        {y: '5D', fab: 2778, qc: 0},
                        {y: '4D', fab: 4912, qc: 0},
                        {y: '3D', fab: 3767, qc: 0},
                        {y: '2D', fab: 6810, qc: 0},
                        {y: '1D', fab: <?php echo $sumWeightYesterday; ?>, qc: 0},
                        {y: 'NOW', fab: 4820, qc: 0}
                    ],
                    parseTime: false,
                    xkey: 'y',
                    ykeys: ['fab', 'qc'],
                    labels: ['FAB', 'QC'],
                    lineColors: ['#a0d0e0', '#3c8dbc'],
                    hideHover: 'auto'
                });

I want to use $sumWeightYesterday but it displays 0 on the data.

Please help me, Thanks

You can try it.

var sumWeightYesterday = <?php echo $sumWeightYesterday; ?>

var area = new Morris.Area({
                    element: 'revenue-chart',
                    resize: true,
                    data: [
                        {y: '6D', fab: 20004, qc: 0},
                        {y: '5D', fab: 2778, qc: 0},
                        {y: '4D', fab: 4912, qc: 0},
                        {y: '3D', fab: 3767, qc: 0},
                        {y: '2D', fab: 6810, qc: 0},
                        {y: '1D', fab: sumWeightYesterday, qc: 0},
                        {y: 'NOW', fab: 4820, qc: 0}
                    ],
                    parseTime: false,
                    xkey: 'y',
                    ykeys: ['fab', 'qc'],
                    labels: ['FAB', 'QC'],
                    lineColors: ['#a0d0e0', '#3c8dbc'],
                    hideHover: 'auto'
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM