使用表单提交事件创建高级图表

时间:2012-03-14 13:53:01

标签: php highcharts

在我的信息中心中,我使用highcharts创建了2个图表。一个图表在加载时自动显示另一个图表想要根据下拉框中选择的值进行更改。

我使用php根据下拉框选择获取数据库值。并将其传递给t0 java脚本以生成图表。

我的问题是它没有显示第二张图表。

这是我的代码:

    var chart1;
      //$(document).ready(function() {
      $("#chartvalue").submit(function() {
       var su=<?php echo json_encode($_SESSION['successcalls']) ?>;
var fail=<?php echo json_encode($_SESSION['failurecalls']) ?>;
var da=<?php echo json_encode($_SESSION['datename']) ?>;
alert(su);
chart1 = new Highcharts.Chart({
    chart: {
        renderTo: 'chartmon_div',
        defaultSeriesType: 'line',
        marginRight: 130,
        marginBottom: 25
    },
    title: {
        text: 'Call Details',
        x: -20 //center
    },
    subtitle: {
        x: -20
    },
    xAxis: {

        categories: da
    },
    yAxis: {
        title: {
            text: 'Total calls'
        },
        plotLines: [{
            value: 0,
            width: 1,
            color: '#808080'
        }]
    },
    tooltip: {
        formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                this.x +': '+ this.y ;
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'top',
        x: -10,
        y: 100,
        borderWidth: 0
    },
    series: [{
        name: 'Success',
        data: su
    }, {
        name: 'Failure',
        data: fail
    }]
            });
        });
            //});
            </script>

我在表格提交中有php varles代码

1 个答案:

答案 0 :(得分:0)

使用PHP条件加密您的高保真javascript

<?php if(isset($_POST['variable'])) {
foreach ($productname as $prdkey => $prdval){
    foreach ($typecount as $typekey => $typeval)
    {
        switch ($typeval) {
            case 0:
                if($producttotal[$prdval][0] != '')
                {
                  $pricecustomstr .= round($producttotal[$prdval][0]).', ';
                  //$pricecustomtotal = $pricecustomtotal + $producttotal[$prdval][0];  
                }
                else
                {
                  $pricecustomstr .= '0, ';     
                }
                break;

            case 1:
                if($producttotal[$prdval][1] != '')
                {
                  $priceuploadstr .= round($producttotal[$prdval][1]).', ';
                  //$priceuploadtotal = $priceuploadtotal + $producttotal[$prdval][1];
                }
                else
                {
                  $priceuploadstr .= '0, ';     
                }
                break;

            case 2:
                if($producttotal[$prdval][2] != '')
                {
                  $pricepredefinedstr .= round($producttotal[$prdval][2]).', ';
                  //$pricepredefinedtotal = $pricepredefinedtotal + $producttotal[$prdval][2];  
                }
                else
                {
                  $pricepredefinedstr .= '0, ';     
                }
                break;

            default:
                if($producttotal[$prdval][0] != '')
                {
                  $pricecustomstr .= round($producttotal[$prdval][0]).', '; 
                }
                else
                {
                  $pricecustomstr .= '0, ';     
                }
                break;
        }
    }

}

$productstring;
$pricecustomstr = rtrim(trim($pricecustomstr),', ');
?>
<script type="text/javascript">
// highchart js code
plotOptions: {
                    series: {
                        stacking: 'normal'
                    }
                },
                    series: [{
                    name: 'Custom Design',
                    data: [<?php echo $pricecustomstr; ?>]
                }, {
                    name: 'Upload Design',
                    data: [<?php echo $priceuploadstr; ?>]

            });
</script>
<?php } ?>

由于