Google图表 - XLS y轴比例数据

时间:2013-02-18 15:12:20

标签: dynamic charts xls

早上好 我正在使用一个动态网站,当xls电子表格发送到服务器时,它会为Google Chart生成图形。

每月,有5个工作表。 3个工作表中,比例值介于0和50之间,其值为0,12.5,25,37.5和50.其中两个值介于0到60之间,值为0,15 ,30,45和60。

两种类型的比例的PHP代码都是相同的。但在某些情况下,电子表格是正确的(值为0,12.5等,或0,15,30等),在其他情况下,它只是忽略它,并且只播放0的数据, 15,30等...

我想知道谷歌图表在哪里拉数据以生成比例,我该怎么做才能始终正确显示比例(第1,2和3页,分数在0到50之间,第4和第5页,有范围)在0到60之间。)

附上代码。

  <?php 
function showDate( $current ){

    $ano = substr($current, 0, 4);
    $mes = substr($current, 5);

    switch ($mes){
        case 1: $mes = 'Janeiro'; break;
        case 2: $mes = 'Fevereiro'; break;
        case 3: $mes = 'Março'; break;
        case 4: $mes = 'Abril'; break;
        case 5: $mes = 'Maio'; break;
        case 6: $mes = 'Junho'; break;
        case 7: $mes = 'Julho'; break;
        case 8: $mes = 'Agosto'; break;
        case 9: $mes = 'Setembro'; break;
        case 10: $mes = 'Outubro'; break;
        case 11: $mes = 'Novembro'; break;
        case 12: $mes = 'Dezembro'; break;
    }

    printf("%s/%s", $mes, $ano);

}


define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
status_header('200');

$produto = get_post(esc_html($_GET['pro']));

$produto_sheet = array(
    'cp-ii-f-32'    => "CP II-F",
    'cp-ii-z-32'    => "CP II-Z",
    'cp-iv-32'      => "CP IV",
    'cp-v-ari'      => "CP V",
    'cp-v-ari-rs'   => "CP V-RS"
);

require( dirname( __FILE__ ) . '/_theme/PHPExcel.php' );


$meta = get_option('opcoes_relatorio');
$directories = wp_upload_dir();

$current = isset($_GET['chave']) ? $_GET['chave'] : '';

foreach($meta as $key => $value){

    if(substr($key, 5) == 13) continue;

    $menu[] = array(
        'class' => $current == $key ? ('current') : (''),
        'label' => substr(getMonthName(substr($key, 5)), 0, 3) . ' ' . substr($key, 0, 4),
        'chave' => $key
    );

    $ano[] = substr($key, 0, 4);
    $mes[] = substr($key, 5);

}

array_multisort($ano, $mes, $menu, SORT_NUMERIC);
if($current == ''){

    $current =  $menu[count($menu)-1]['chave'];
    foreach($menu as &$m){
        if($m['chave'] == substr($current, 0, 4) . '-' . (int)substr($current, 5)){
            $m['class'] = 'current';
        }
    }
}



$xls['file'] = $directories['basedir'];
$xls['sub'] = preg_replace('~(.*)?([0-9]{4}/[0-9]{2}/.*\.xls)~', '$2', $meta[$current]);

if( (int)substr($current, 5) != 13 ){
    $rows = getValuesRelatorio($xls['file'].'/'.$xls['sub'], $produto_sheet[$produto->post_name]);
    //$minimo[0] = 0; 
    //$minimo[1] = 10; 
    //$minimo[2] = 20; 
    //$minimo[3] = 32; 
    $minimo = getMinimoAnualRelatorio($xls['file'].'/'.$xls['sub'], $produto_sheet[$produto->post_name]);
} else {
    $rows = getMediaAnualRelatorio($xls['file'].'/'.$xls['sub'], $produto_sheet[$produto->post_name]);
    $minimo = getMinimoAnualRelatorio($xls['file'].'/'.$xls['sub'], $produto_sheet[$produto->post_name], 34);
}

$media = array();
foreach($rows['media'] as $row){
    if($row[0] == "Média"){
        for($i = 1; $i < 5; $i++){
            $media[] = $row[count($row)-$i];
        }
    }
}

foreach ($minimo as $key => $value) {
    $minimo[$key] = str_replace(',', '.', $minimo[$key]);
}

foreach ($media as $key => $value) {
    $media[$key] = str_replace(',', '.', $media[$key]);
}

&GT;

<body>

    <div id="logo"><img src="_assets/images/master/header-logo.png" alt="" /></div>

    <h2><?php echo $produto->post_title; ?> <br /><span><?php showDate($current); ?></span></h2>

    <div class="wrap">

        <table cellpadding="0" cellspacing="0" border="0" class="green-table">
            <thead>
                <tr>
                    <th rowspan="3" class="data">Data</th>
                    <th colspan="10">QUÍMICOS</th>
                    <th colspan="11" class="fisicos">FÍSICOS</th>
                </tr>
                <tr class="gray-01">
                    <th>Al<sub>2</sub>O<sub>3</sub></th>
                    <th>SiO<sub>2</sub></th>
                    <th>Fe<sub>2</sub>O<sub>3</sub></th>
                    <th>CaO</th>
                    <th>MgO</th>
                    <th>SO<sub>3</sub></th>
                    <th>P. Fogo</th>
                    <th>CaO&nbsp;L.</th>
                    <th>R. Ins.</th>
                    <th>Eq. Alc</th>
                    <th>Exp.</th>
                    <th colspan="2">Tempo de<br />Pega (h:min)</th>
                    <th>Cons.<br />Normal</th>
                    <th>Blaine</th>
                    <th>#<br />200</th>
                    <th>#<br />325</th>
                    <th colspan="4">Resist&ecirc;ncia &agrave;<br />Compress&atilde;o (MPa)</th>
                </tr>
                <tr  class="gray-02">
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>%</th>
                    <th>mm</th>
                    <th>Início</th>
                    <th>Fim</th>
                    <th>%</th>
                    <th>cm&sup2;/g</th>
                    <th>%</th>
                    <th>%</th>
                    <th>1 dias</th>
                    <th>3 dias</th>
                    <th>7 dias</th>
                    <th>28 dias</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    $duasCasas = array(1,2,3,4,5,6,7,8,9,10,11,16,17);
                    $umaCasa = array(14,18,19,20,21);
                    $nenhumaCasa = array(0,15);
                    $duasCasasSd = array(1,2,3,4,5,6,7,8,9,10,11,16,17);
                    $umaCasaSd = array(14,18,19,20,21);
                    $nenhumaCasaSd = array(0);
                ?>
                <?php if(isset($rows['values'])): foreach($rows['values'] as $row): ?>
                <tr>
                    <?php foreach($row as $key=>$cell): ?>
                    <?php 
                    if(!is_numeric($cell)){
                        preg_match("~[0-9]~", $cell, $matches);

                        if(empty($matches)){
                            $cell = "-";
                        }
                    } else if (in_array($key,$nenhumaCasa)) {
                        $cell = number_format($cell,0,',','.');
                    } elseif (in_array($key,$umaCasa)) {
                        $cell = number_format($cell,1,',','');
                    } elseif (in_array($key,$duasCasas)) {
                        $cell = number_format($cell,2,',','');
                    }  ?>
                    <td><?php echo $cell; ?></td>
                    <?php endforeach; ?>
                </tr>
                <?php endforeach; endif;    ?>

                <?php foreach($rows['media'] as $rowKey=>$row): ?>
                <tr style="font-weight: bold;">
                    <?php foreach($row as $key=>$cell): ?>
                    <?php 

                    if($cell == "Sd"){
                        $sd = true;
                    }
                    if ($sd && $key == 15){
                        #$cell = number_format($cell,2,',','.');
                        $cell = explode(".", $cell);
                        $cell = number_format($cell[0],0,',','.') . "," . substr($cell[1], 0, 2);
                        $sd = null;
                    } else if($rowKey == 15 && $key == 15)
                    {
                        $cell = number_format($cell,2,',','');
                    } else if($rowKey == 24 && $key == 15)
                    {
                        $cell = number_format($cell,0,',','.');
                    } else {
                        if (in_array($key,$nenhumaCasa) && $key != 0) {
                            $cell = number_format($cell,0,',','.');
                        } elseif (in_array($key,$umaCasa)) {
                            $cell = number_format($cell,1,',','');
                        } elseif (in_array($key,$duasCasas)) {
                            $cell = number_format($cell,2,',','');
                        }
                    } 
                      ?>
                    <td><?php echo $cell; ?></td>
                    <?php endforeach; ?>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <?php 
            foreach($minimo as $val){
                $nMinimo[] = intval($val);
            }
            foreach(array_reverse($media) as $val){
                $nMedia[] = number_format($val, 1);
            }
        ?>

        <img class="chart" src="http://chart.apis.google.com/chart?chxl=0:|1|3|7|28|1:|Dias|2:|12%2C5|25%2C5|37%2C5|50%2C0&chxt=x,x,y&chxp=0,3.5,10.5,17.5,24.5,0|1,1.7|2,12.5,25.5,37.5,50&chxr=0,0,28|1,4,0|2,-5,50&chxs=0,676767,11.5,0,lt,676767&chxtc=0,10&chbh=a,0,11&chs=400x260&cht=bvg&chco=e6a736,60791b&chds=0.1,50,0.1,50&chd=t:<?php echo implode(',', $nMinimo); ?>|<?php echo implode(',', $nMedia); ?>&chdl=Minimos|Médios&chtt=<?php urlencode($produto->post_title); ?>&chm=N,666666,0,-1,11|N,666666,1,-1,11" width="400" height="260" alt="Vertical bar chart" />

        <div class="produtos-obs">
            <dl class="green-box">
                <dt>Obs</dt>
                <dd>
                    <p>
                        <small>
                            <?php echo get_post_meta($produto->ID, 'observacoes', true); ?>
                        </small>
                    </p>
                </dd>
            </dl>
        </div>

        <dl id="legend" class="green-box">
            <dt></dt>
            <dd>
                <p><small>
                    Valores mínimos - NBR <?php echo get_post_meta($produto->ID, "nbr", true); ?> <br />
                    Valores médios - <?php echo $produto->post_title; ?>
                </small></p>
            </dd>
        </dl>

    </div>
</body>

<script type="text/javascript">
    window.print();     
</script>

Google图表代码

    <img class="chart" src="http://chart.apis.google.com/chart?chxl=0:|1|3|7|28|1:|Dias|2:|12%2C5|25%2C5|37%2C5|50%2C0&chxt=x,x,y&chxp=0,3.5,10.5,17.5,24.5,0|1,1.7|2,12.5,25.5,37.5,50&chxr=0,0,28|1,4,0|2,-5,50&chxs=0,676767,11.5,0,lt,676767&chxtc=0,10&chbh=a,0,11&chs=400x260&cht=bvg&chco=e6a736,60791b&chds=0.1,50,0.1,50&chd=t:<?php echo implode(',', $nMinimo); ?>|<?php echo implode(',', $nMedia); ?>&chdl=Minimos|Médios&chtt=<?php urlencode($produto->post_title); ?>&chm=N,666666,0,-1,11|N,666666,1,-1,11" width="400" height="260" alt="Vertical bar chart" />

谢谢

0 个答案:

没有答案