Pie Graph点击Highcharts

时间:2014-05-01 02:26:28

标签: highcharts

我有一个图表,可以在选择一块饼时打开一个颜色框。但是,我试图对此进行权限处理,以便如果一个特定的人是一组允许的饼图,则允许点击,否则忽略它。

是否有一些建议你可以给我指出正确的方向?

我的数组名为$ allowedRegs,它将返回NE,NW,SW,$ person变量包含员工ID号。 getRegMgr()函数应该返回允许的员工的ID号。这是允许的吗?

    <script type="text/javascript">
$(document).ready(function() {

Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
            return {
                radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
                stops: [
                    [0, color],
                    [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
                ]
            };
        });


$('#container').highcharts({
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        backgroundColor: null
    },
    title: {
        text: ''
    },

    tooltip: {
        pointFormat: '{series.name}: <b>${point.y}</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                color: '#000000',
                connectorColor: '#000000',
                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
            }
        }
    },
    series: [{
        type: 'pie',
                events: {
                    click: function(e) {
                        //window.console.log(this);
                        var point       = e.point.name;
                        var explode     = point.split("~");
                        var loc         = explode[0];
                        var person      = <?php echo $respid;?>


                <?php 

                if(in_array($person, getRegMgr($allowedRegs))) {

                ?>              
                    $.colorbox({ iframe:true, width:"90%", height:"90%", href: "reportDetails.php?dept=<?php echo $dept;?>&fy=<?php echo $selectedFy;?>&location="+loc+"&person="+person});

                <?php } ?>

                    }
                },

        name: 'Total Revenue Earned:',
        data: [

                <?php
                    foreach($regionId as $region) {
                    //Get Data
                    $getData = mysql_query("SELECT SUM(hire_net) as rentalRev FROM dw_invoice LEFT JOIN dw_rep_zips ON dw_invoice.zip = dw_rep_zips.zip WHERE contract_type='H' and region = '".$region."' and invoice_date >= '".$fyStart."' AND invoice_date < '".$fyEnd."' GROUP BY region") or die("Cannot get data: " . mysql_error());

                    if(mysql_num_rows($getData) > 0) {
                        while($row = mysql_fetch_assoc($getData))
                            {
                            echo "['".getRegName($region)."', " . $row["rentalRev"]."], ";
                            }
                        }
                    }
                ?>
            ]
    }]
});
 });
</script>

1 个答案:

答案 0 :(得分:0)

更好的是在javascript中设置全局变量,这个值正在形成PHP。然后,只有在点击事件中添加你需要的东西。

if(globalVariablePermission) 
  //do this
else
  return false;