0

我正在使用谷歌图表创建折线图。我在谷歌搜索下面有这些代码。如何为这些代码行添加线条样式(虚线)的属性?

$sth = mysql_query("SELECT * FROM table");

$rows = array();
//flag is not needed
$flag = true;
$table = array();
$table['cols'] = array(

    array('label' => 'Month', 'type' => 'string'),
    array('label' => 'a', 'type' => 'number'),
    array('label' => 'b', 'type' => 'number'),
    array('label' => 'c', 'type' => 'number'),
    array('label' => 'd', 'type' => 'number')

);

$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $temp = array();

    $temp[] = array('v' => (string) $r['Month']); 

    // Values of each slice
    $temp[] = array('v' => $r['a']);

    // Values of each slice
    $temp[] = array('v' => $r['b']);

    // Values of each slice
    $temp[] = array('v' => $r['c']);

    // Values of each slice
    $temp[] = array('v' => $r['d']); 
    $rows[] = array('c' => $temp);

}

$table['rows'] = $rows;
$jsonTable = json_encode($table);
//echo $jsonTable;
4

2 回答 2

0

非常感谢!!我将我的 php 编码放入您的代码中,它可以正常工作。

  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Month');
    data.addColumn('number', 'a');
    data.addColumn('number', 'b');
    data.addColumn({type: 'boolean', role: 'certainty'});
    data.addRows([

        <?php
        $sql="SELECT * FROM table";
        $result=mysql_query($sql);

        while($row=mysql_fetch_array($result)){

        $id= $row['id'];
        $month=$row['Month'];
        $a=$row['a'];
        $b=$row['b'];
        if ($a=="NULL"){$a = "";}
        if ($b=="NULL"){$b = "";}
        echo "['" . $month . "'," . $a . "," . $b . "," . "false" . "]";
        echo ",";

        }
        ?>  
    ]);

    var options = {
        title: 'Company Performance'
    };

    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    chart.draw(data, options);
  }
于 2013-07-24T04:09:05.817 回答
0

使用虚线可以实现确定性作用。根据您希望线条虚线的方式,您只需添加一个适当的“真/假”列,其中每个点都有一个值,列角色分配为“确定性”,如下例所示。

  google.load('visualization', '1.1', {'packages':['corechart']});
  google.setOnLoadCallback(drawChart_C7);

  function drawChart_C7() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Year');
    data.addColumn('number', 'Sales');
    data.addColumn({type: 'boolean', role: 'certainty'});
    data.addColumn('number', 'Expenses');
    data.addColumn({type: 'boolean', role: 'certainty'});
    data.addRows([
      ['2004', 1000, false, 400, true],
      ['2005', 1170, true, 460, true],
      ['2006', 660, true, 1120, false],
      ['2007', 1030, true, 540, false]
    ]);

    var chart = new google.visualization.LineChart(document.getElementById('chart_C7'));
    chart.draw(data, {width: 400, height: 240, legend:'top'});
  }
于 2013-07-12T08:15:46.617 回答