highcharts从数据库表中提取数据

时间:2014-02-04 15:41:28

标签: php mysql database highcharts

演示我正在使用的内容:http://jsfiddle.net/98Fuq/4/

我使用

在x轴上显示了作业编号
$sql = "SELECT * FROM view_job_budgetreport";
$result = mysqli_query($dbc3, $sql);
while($row = mysqli_fetch_assoc($result)) {
    $jobNum[] = $row['Job_Num'];
}

然后在我的代码中:

var colors = Highcharts.getOptions().colors,
categories = [<?php echo join($jobNum, ',') ?>], //I display the job nums here
name = '% of budgeted hours',
level = 0,
data = [{
      y: 300,
      color: colors[0],
      drilldown: {
         name: 'Job # Detailed Overview',
         categories: ['Surfacing', 'Design', 'Details', 'Ejector', 'EDM', 'GD/BM', 'CNC', 'Mold Making', 'Spotting', 'Spotting Line', 'Handwork', 'Tryout'  ],
         level: 1,
         data: [{
             y: 30,
             drilldown: {
                 level: 2,
                 name: 'Job # Machining Overview',
                 categories: ['CNC 1', 'CNC 2', 'CNC 3', 'CNC4', 'Gun Drill 1', 'Gun Drill 2', 'Boring Mill 1', 'Boring Mill 2', 'EDM 1', 'EDM 2', 'EDM 3'],
                 data: [23,54,47, 58, 42, 10, 34, 78, 10, 55, 25],
                 color: colors[3]
             }
         }, 40, 7.35, 2.41, 200, 100, 50, 75, 86, 95, 75, 25],
         color: colors[2]
      }
   }

现在这个部分运作良好,但是我不能为我的生活弄清楚钻取的第2级和第3级。我尝试使用与用于工作号码相同的方法。

表格结构:

Table Structure

1 个答案:

答案 0 :(得分:1)

像这样更改你的php,所以你得到了你需要的所有值;

$sql = "SELECT * FROM view_job_budgetreport";
$result = mysqli_query($dbc3, $sql);
while($row = mysqli_fetch_assoc($result)) {
    $jobNum[] = $row['Job_Num'];
    $jobData[$row['Job_Num']] = $row['Job_Y'];
    $jobDrillData[$row['Job_Num']][] = $row;
}

然后在highcharts中循环这些变量

相关问题