多列阵准备图表

时间:2014-02-20 18:30:56

标签: php mysql multidimensional-array while-loop pchart

我搜索了答案,却找不到答案。这是漫长而复杂的,寻找比我聪明的人回答。

情况如下。使用PHP,SQL和尝试Pchart。

1)请不要建议其他图表工具。这是浪费你的时间和我的。其他图表工具提供JAVA,JAVASCRIPT,JQUERY等。它们很光滑,但我需要的是简单的(服务器端创建动态创建的数据并使用服务器上的内容进行渲染。为什么要将负载放在客户端 - 至少在我调查时是这样。

2)这是PHP特定的问题而不是pchart工具。

以下是该方案。

我有一张游泳结果表。

我可以按照我需要的方式格式化数据。

见下面的照片。

数组(假设这是第一个数组)

(
    [0] => Freestyle 50
    [1] => Freestyle 100
    [2] => Backstroke 50
    [3] => Butterfly 50
    [4] => Medley 100
)

数组(假设这是第二个数组)

(
    [Backstroke 50] => Array
        (
            [2012-11-04] => 51.08
            [2012-11-10] => 52.50
            [2012-11-25] => 55.48
            [2012-12-01] => 47.56
            [2012-12-08] => 44.51
            [2012-12-15] => 49.46
            [2013-01-19] => 47.12
            [2013-11-03] => 42.52
            [2013-11-09] => 40.94
            [2013-11-10] => 42.97
            [2013-11-16] => 41.36
            [2013-12-01] => 45.16
            [2013-12-08] => 40.59
            [2014-01-12] => 37.67
            [2014-02-01] => 37.70
        )

    [Freestyle 50] => Array
        (
            [2012-11-04] => 45.33
            [2012-11-25] => 50.12
            [2013-11-03] => 37.01
            [2013-11-10] => 36.73
            [2013-12-01] => 39.94
            [2014-01-04] => 39.77
            [2014-01-12] => 34.22
            [2014-02-01] => 34.93
        )

    [Freestyle 100] => Array
        (
            [2012-11-04] => 137.73
            [2012-11-10] => 126.86
            [2012-12-08] => 133.65
            [2013-11-03] => 124.14
            [2013-11-10] => 121.94
            [2013-11-16] => 121.10
            [2013-12-01] => 130.99
            [2013-12-07] => 118.27
            [2013-12-08] => 122.44
            [2014-01-04] => 131.38
            [2014-01-11] => 115.95
            [2014-01-18] => 120.06
        )

    [Medley 100] => Array
        (
            [2012-12-01] => 146.66
            [2013-01-19] => 143.88
            [2013-11-03] => 137.37
            [2013-11-09] => 133.05
            [2013-11-10] => 134.69
            [2013-12-01] => 145.29
            [2013-12-07] => 130.15
            [2013-12-08] => 130.92
            [2014-01-12] => 129.33
            [2014-01-18] => 130.81
            [2014-02-01] => 128.57
        )

    [Butterfly 50] => Array
        (
            [2013-12-08] => 46.82
            [2014-01-12] => 43.66
        )

)

数组(假设这是第三个数组)

(
    [2] => 2012-11-04
    [14] => 2012-11-10
    [1] => 2012-11-25
    [31] => 2012-12-01
    [15] => 2012-12-08
    [26] => 2012-12-15
    [24] => 2013-01-19
    [7] => 2013-11-03
    [28] => 2013-11-09
    [4] => 2013-11-10
    [11] => 2013-11-16
    [3] => 2013-12-01
    [9] => 2013-12-07
    [12] => 2013-12-08
    [5] => 2014-01-04
    [10] => 2014-01-11
    [0] => 2014-01-12
    [13] => 2014-01-18
    [6] => 2014-02-01
)

为了排列图表工具,我需要将它放在这样的字符串中。

 ============== Backstroke 50 =================
51.08,52.50,55.48,47.56,44.51,49.46,47.12,42.52,40.94,42.97,41.36,45.16,40.59,37.67,37.70Create or Render Chart

"2012-11-04","2012-11-10","2012-11-25","2012-12-01","2012-12-08","2012-12-15","2013-01-19","2013-11-03","2013-11-09","2013-11-10","2013-11-16","2013-12-01","2013-12-08","2014-01-12","2014-02-01"

============== Freestyle 50 =================
45.33,50.12,37.01,36.73,39.94,39.77,34.22,34.93

"2012-11-04","2012-11-25","2013-11-03","2013-11-10","2013-12-01","2014-01-04","2014-01-12","2014-02-01"

============== Freestyle 100 =================
137.73,126.86,133.65,124.14,121.94,121.10,130.99,118.27,122.44,131.38,115.95,120.06

"2012-11-04","2012-11-10","2012-12-08","2013-11-03","2013-11-10","2013-11-16","2013-12-01","2013-12-07","2013-12-08","2014-01-04","2014-01-11","2014-01-18"

============== Medley 100 =================
146.66,143.88,137.37,133.05,134.69,145.29,130.15,130.92,129.33,130.81,128.57

"2012-12-01","2013-01-19","2013-11-03","2013-11-09","2013-11-10","2013-12-01","2013-12-07","2013-12-08","2014-01-12","2014-01-18","2014-02-01"

============== Butterfly 50 =================
46.82,43.66

"2013-12-08","2014-01-12" 

我想要实现的是假设数组#3。要插入上面所有这些列表中。示例:蝴蝶有两个日期。但我想显示所有日期,并插入日期的空闲时间。这将允许在图表上呈现的线条充分利用显示的日期。

以下是代码:

First Array:在此之下加上第三个数组:

        while($result->fetchInto($data,DB_FETCHMODE_ASSOC)) {
            $count ++;
            $stroke = $data['stroke'];
            $distance = $data['distance'];
            $start = mysql2date($data['start']);
            $dateARR[] = $data['start'];
            $stroke = trim($c->getStrokeName($stroke));
            $strokestr = $stroke . " " . $distance;
            if($strokestr != $lastEvent) {
                $strokeARR[] = $strokestr;
                $lastEvent = $strokestr;
            }
            $lastEvent = $strokestr;

        }
        $dateARR = array_unique($dateARR);
        asort($dateARR);

第二阵列:

while($result->fetchInto($data,DB_FETCHMODE_ASSOC)) {
                $stroke = $data['stroke'];
                $distance = $data['distance'];
                $start = mysql2date($data['start']);
                $time = $c->integer2time($data['time']);
                $time = str_replace(':', '', $time);
                $meet = $data['meet'];
                $stroke = trim($c->getStrokeName($stroke));
                $strokestr = $stroke . " " . $distance;
                $timeARR[$strokestr][$data['start']] = $time;
                $count ++;
            }

应该或如何在第二个数组中使用while循环2并插入缺少的日期。我应该预先填写日期,然后在循环期间进行比较,以便在构建时间ARR时放置时间或时间的VOID吗?

有任何想法吗?

1 个答案:

答案 0 :(得分:0)

现在想出来。

// Loop through Stroke and add all dates.       
    foreach ($strokeARR as $key1 => $val1) {
        print "$key1 = $val1\n";
        foreach ($dateARR as $key2 => $val2) {
            print "$key2 = $val2\n";
            $TestARR[$val1][$val2] = "VOID";
        }
    }

我必须循环并预先填写完整的日期范围,然后预先填写VOID。 当我进入第二个while循环时,我最终在需要的地方插入时间。解决了。我希望我能一次性做到这一点,但我不是那么好。