Highchart没有在cakephp中显示

时间:2013-12-05 12:45:22

标签: php cakephp highcharts cakephp-2.3

我正在开发一个cakephp网站,我在哪里使用HighchartPHP库。但高图表没有显示。这个问题只有当我使用数据库中的动态数据时,如果我使用静态数组传递,那么它将使用相同的代码正常工作。

下面是我使用的动态代码得到的数组:

stdClass Object
(
    [series] => Array
        (
            [0] => Array
                (
                    [name] => Forwarding Facility 1
                    [data] => Array
                        (
                            [0] => 28.5
                            [1] => 410.68
                            [2] => 0
                            [3] => 0
                        )

                )

            [1] => Array
                (
                    [name] => Forwarding Facility 2
                    [data] => Array
                        (
                            [0] => 0
                            [1] => 0
                            [2] => 99.05000000000001
                            [3] => 0
                        )

                )

            [2] => Array
                (
                    [name] => Forwarding Facility 3
                    [data] => Array
                        (
                            [0] => 0
                            [1] => 15.7
                            [2] => 0
                            [3] => 0
                        )

                )

            [3] => Array
                (
                    [name] => Hampshire Turf
                    [data] => Array
                        (
                            [0] => 0
                            [1] => 540
                            [2] => 0
                            [3] => 0
                        )

                )

        )

)

下面是我从demo:

中的一个示例中使用的静态数据数组
    stdClass Object
(
    [series] => Array
        (
            [0] => Array
                (
                    [name] => John
                    [data] => Array
                        (
                            [0] => 5
                            [1] => 3
                            [2] => 4
                            [3] => 7
                            [4] => 2
                        )

                )

            [1] => Array
                (
                    [name] => Jane
                    [data] => Array
                        (
                            [0] => 2
                            [1] => 2
                            [2] => 3
                            [3] => 2
                            [4] => 1
                        )

                )

            [2] => Array
                (
                    [name] => Joe
                    [data] => Array
                        (
                            [0] => 3
                            [1] => 4
                            [2] => 4
                            [3] => 2
                            [4] => 5
                        )

                )

        )

)

我已经花了2天时间来解决它,但我找不到相同的解决方案。

有人可以帮帮我吗?非常感谢!

谢谢, Chandresh

2 个答案:

答案 0 :(得分:2)

我尝试了很多不同的方法,但发现了非常简单的解决方案。 <强>铸造即可。 是的,不知何故,当传递给highcharts时,它需要TYPE CASTE数组值。 所以我使用 floatval()函数将数据转换为浮点值。最后它的工作就像一个魅力!

感谢大家的回复和支持!

答案 1 :(得分:1)

你尝试过这样的事吗?

                        [0] => '0'
                        [1] => '0'
                        [2] => '99.05000000000001'
                        [3] => '0'

或您的数组值为$ something = '99 .0500000000001';

                        [0] => 0
                        [1] => 0
                        [2] => $something
                        [3] => 0