如何使增长宝图与mysql + PDO中的数据 [英] How make a growth baby chart with data in mysql +PDO

查看:205
本文介绍了如何使增长宝图与mysql + PDO中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个图表与成长婴儿表我有在DB ...我失去了想法,现在我不知道该怎么做... 这是我需要显示的图表,当医生插入每个孩子的身高和体重...需要显示插入(灰线)...



这里是我的代码,直到现在

em>( ):

 <?php 
'includes / configs.php';
/ *
* $ normal是一个(edad => peso)键/值对的数组
* $ desnutricion是一个(edad => peso)键/
* $ desnutricionSevera是一个(edad => peso)键/值对的数组
*
*你可以硬编码或从数据库中拉取, b $ b * /
$ sql = $ conn-> prepare(SELECT * FROM ESTATURA WHERE edad<>'AND peso"'AND AND id_paciente = 1);
$ sql-> execute();
$ data = array(array('Meses',$ apellido,'Normal','Desnutricion','Desnutricion Severa'));
while($ row = $ sql-> fetch(PDO :: FETCH_ASSOC)){
$ edad = $ row ['edad'];
//使用(int)将值解析为整数
//或(float)将值解析为浮点数
//使用适当的值
$ edad =(int)preg_replace('/ \D /','',$ edad);
$ peso = $ row ['peso'];
$ peso =(float)preg_replace('/ \D /','',$ peso);

$ data [] = array($ peso,$ edad,$ normal [$ edad],$ desnutricion [$ edad],$ desnutricionSevera [$ edad]);
$ data1 [] = array($ peso,$ edad);
}
?>
<!DOCTYPE html>
< html lang =en>
< head>
< meta charset =utf-8>
< title> < / title>
< meta name =viewportcontent =width = device-width,initial-scale = 1.0/>
< script type =text / javascriptsrc =https://www.google.com/jsapi>< / script>
< script type =text / javascript>
google.load(visualization,1,{packages:[corechart]});
google.setOnLoadCallback(drawChart);
function drawChart(){
var data = google.visualization.arrayToDataTable([<?php echo json_encode($ data);?>]);
//通过Meses对数据进行排序,以确保它是正确的顺序
data.sort(0);

var options = {
title:'Grafica de Crecimiento deniñas de 0 a 24 meses',
hAxis:{
title:'Meses',
titleTextStyle:{color:'#333'}
},
vAxis:{
minValue:0
},
系列:{
0:{
<?php echo implode(,,$ peso); >
type:'line'
},
1:{
//正常重量的系列选项
type:'area'
},
2:{
//用于desnutricion的系列选项
类型:'area'
},
3:{
// $ b type:'area'
}
}
};

var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data,options);
}
< / script>
< / head>
< body>
< div id =chart_divstyle =width:800px; height:400px;>< / div>
< / body>
< / html>

我不明白如何可以插入默认变量(正常,desnutricion和desnutricion severa)我需要创建一个新的表与默认数据,然后使一个联合?

$

b
$ b

 <?php 
include'includes / configs.php';

$ sql = $ conn-> prepare(SELECT nombre,apellido,edad,peso FROM ESTATURA WHERE edad<>'AND peso<>
$ sql-> execute();
while($ row = $ sql-> fetch(PDO :: FETCH_ASSOC)){
$ nombre = trim(addslashes($ row ['nomipse']));
$ lapellido = trim(addslashes($ row ['apellido']));
$ edad = $ row ['edad'];
$ edad = preg_replace('/ \D /','',$ edad);
$ peso = $ row ['peso'];
$ peso = preg_replace('/ \D /','',$ peso);

$ myurl [] =['。$ nombre。。$ apellido。'$ edad。,。$ peso。


}

print_r($ myurl);
echo implode(,,$ myurl);
?>
< script type =text / javascriptsrc =https://www.google.com/jsapi>< / script>
< script type =text / javascript>
google.load(visualization,1,{packages:[corechart]});
google.setOnLoadCallback(drawChart);
function drawChart(){
var data = google.visualization.arrayToDataTable([
['Meses','Normal','Desnutrición','DesnutriciónSevera'],
/ * ['0',4.23,2.39,2.00],
['1',5.55,3.10,2.85],
['2',6.75,3.95,3.41],
['3',7.60,4.50,4.00],
['4',8.23,5.00,4.40],
['5',8.81,5.38,4.80],
[ 6',9.30,5.71,5.11],
['7',9.87,6.00,5.38],
['8',10.19,6.21,5.58],
['9' ,10.56,6.47,5.76],
['10',10.95,6.66,5.95],
['11',11.20,6.80,6.10],
['12',11.55 ,7.00,6.21],
['13',11.91,7.20,6.40],
['14',12.10,7.38,6.58],
['15',12.37,7.54 ,6.77],
['16',12.60,7.75,6.85],
['17',12.96,7.86,7.00],
['18',13.16,8.05,7.20 ],
['19',13.41,8.20,7.31],
['20',13.72,8.38,7.42],
['21',14.02,8.49,7.61]
['22',14.24,8.70,7.79],
['23',14.68,8.90,7.95],
['24',14.90,9.00,8.00] * /
<?php echo implode(,,$ myurl); >
]);

var options = {
title:'Grafica de Crecimiento deniñas de 0 a 24 meses',
hAxis:{title:'Meses',titleTextStyle:{color :'#333'}},
vAxis:{minValue:0}
};

var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data,options);
}
< / script>

< div id =chart_divstyle =width:800px; height:400px;>< / div>

/*.....*/ 是我需要显示的数据在mysql ...但我喜欢的百分位数,因为图表不显示时,该数据没有 /*...*/ code>



这里的图表现在..

最好的问候

/ p>

AndrésValencia

解决方案

这是您需要的基本框架使这项工作:

  / * 
* $ normal是一个数组(edad => peso)值对
* $ desnutricion是(edad => peso)键/值对的数组
* $ desnutricionSevera是(edad => peso)键/值对的数组
*
*你可以硬编码或从数据库中拉出它们,无论对你有什么作用
* /
$ sql = $ conn-> prepare(SELECT edad,peso FROM ESTATURA WHERE<选择婴儿的标准>);
$ sql-> execute();
$ data = array(array('Meses',$ apellido,'Normal','Desnutricion','Desnutricion Severa'));
while($ row = $ sql-> fetch(PDO :: FETCH_ASSOC)){
$ edad = $ row ['edad'];
//使用(int)将值解析为整数
//或(float)将值解析为浮点数
//使用适当的值
$ edad =(int)preg_replace('/ \D /','',$ edad);
$ peso = $ row ['peso'];
$ peso =(float)$ peso;

$ data [] = array($ edad,$ peso,$ normal [$ edad],$ desnutricion [$ edad],$ desnutricionSevera [$ edad]);
}

然后,在您的javascript:

  function drawChart(){
var data = google.visualization.arrayToDataTable(<?php echo json_encode($ data);?>);
//通过Meses对数据进行排序,以确保它是正确的顺序
data.sort(0);

var options = {
title:'Grafica de Crecimiento deniñas de 0 a 24 meses',
hAxis:{
title:'Meses',
titleTextStyle:{color:'#333'}
},
vAxis:{
minValue:0
},
系列:{
0:{
//此婴儿体重的系列选项
类型:'line'
},
1:{
//正常体重系列选项b $ b type:'area'
},
2:{
//用于desnutricion的系列选项
type:'area'
},
3:{
// desutsricion severa的系列选项
type:'area'
}
}
};

var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data,options);
}

试试看看它是否适合你。


I am trying to make a chart with growth baby table I have in DB... I lost the idea and right now I don't know how to do it... this is the chart I need to show when the doctor insert the height and weight of every child...need to show the inserted the percentiles data and that will depend of the height and weight of the baby to show the graph (gray line)...

here is my code until now (EDITED WITH NEW CODE):

<?php
include 'includes/configs.php';
/*
 * $normal is an array of (edad => peso) key/value pairs
 * $desnutricion is an array of (edad => peso) key/value pairs
 * $desnutricionSevera is an array of (edad => peso) key/value pairs
 * 
 * you can hard-code these or pull them from a database, whatever works for you
 */
$sql = $conn->prepare("SELECT * FROM ESTATURA WHERE edad<>'' AND peso<>'' AND id_paciente = 1");
$sql->execute();
$data = array(array('Meses', $apellido, 'Normal', 'Desnutricion', 'Desnutricion Severa'));
while($row = $sql->fetch(PDO::FETCH_ASSOC))  {
    $edad = $row['edad'];
    // use (int) to parse the value as an integer
    // or (float) to parse the value as a floating point number
    // use whichever is appropriate
    $edad = (int) preg_replace('/\D/', '', $edad);
    $peso = $row['peso'];
    $peso = (float) preg_replace('/\D/', '', $peso);

    $data[] = array($peso, $edad, $normal[$edad], $desnutricion[$edad], $desnutricionSevera[$edad]);
$data1[] = array($peso, $edad);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title> </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", {packages:["corechart"]});
        google.setOnLoadCallback(drawChart);
        function drawChart() {
            var data = google.visualization.arrayToDataTable([<?php echo json_encode($data); ?>]);
            // sort the data by "Meses" to make sure it is in the right order
            data.sort(0);

            var options = {
                title: 'Grafica de Crecimiento de niñas de 0 a 24 meses',
                hAxis: {
                    title: 'Meses',
                    titleTextStyle: {color: '#333'}
                },
                vAxis: {
                    minValue: 0
                },
                series: {
                    0: {
                        <?php echo implode(",", $peso); ?>
                        type: 'line'
                    },
                    1: {
                        // series options for normal weight
                        type: 'area'
                    },
                    2: {
                        // series options for desnutricion
                        type: 'area'
                    },
                    3: {
                        // series options for desnutricion severa
                        type: 'area'
                    }
                }
            };

            var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
            chart.draw(data, options);
        }
    </script>
</head>
<body>
    <div id="chart_div" style="width: 800px; height: 400px;"></div>
</body>
</html>

I don't understand how can insert the default variables (normal, desnutricion and desnutricion severa) with the baby variable.. I need to create a new table with the defaults data and then make a union? or just insert the variables in every series??

--OLD CODE--

<?php
include 'includes/configs.php';

$sql = $conn->prepare("SELECT nombre, apellido, edad, peso FROM ESTATURA WHERE edad<>'' AND peso<>'' ");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC))  {    
    $nombre = trim(addslashes($row['nombre']));
    $lapellido = trim(addslashes($row['apellido']));
    $edad = $row['edad'];
    $edad = preg_replace('/\D/', '', $edad);
    $peso = $row['peso'];
    $peso  = preg_replace('/\D/', '', $peso);

    $myurl[] = "['".$nombre." ".$apellido."', ".$edad.",".$peso."]";


    }    

    print_r($myurl);
    echo implode(",", $myurl);
?>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Meses', 'Normal', 'Desnutrición', 'Desnutrición Severa'],
          /*['0',  4.23,      2.39,      2.00],
          ['1',  5.55,      3.10,      2.85],
          ['2',  6.75,      3.95,      3.41],
          ['3',  7.60,      4.50,      4.00],
          ['4',  8.23,      5.00,      4.40],
          ['5',  8.81,      5.38,      4.80],
          ['6',  9.30,      5.71,      5.11],
          ['7',  9.87,      6.00,      5.38],
          ['8',  10.19,      6.21,      5.58],
          ['9',  10.56,      6.47,      5.76],
          ['10',  10.95,      6.66,      5.95],
          ['11',  11.20,      6.80,      6.10],
          ['12',  11.55,      7.00,      6.21],
          ['13',  11.91,      7.20,      6.40],
          ['14',  12.10,      7.38,      6.58],
          ['15',  12.37,      7.54,      6.77],
          ['16',  12.60,      7.75,      6.85],
          ['17',  12.96,      7.86,      7.00],
          ['18',  13.16,      8.05,      7.20],
          ['19',  13.41,      8.20,      7.31],
          ['20',  13.72,      8.38,      7.42],
          ['21',  14.02,      8.49,      7.61],
          ['22',  14.24,      8.70,      7.79],
          ['23',  14.68,      8.90,      7.95],
          ['24',  14.90,      9.00,      8.00]*/
            <?php echo implode(",", $myurl); ?>
        ]);

        var options = {
          title: 'Grafica de Crecimiento de niñas de 0 a 24 meses',
          hAxis: {title: 'Meses',  titleTextStyle: {color: '#333'}},
          vAxis: {minValue: 0}
        };

        var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>

<div id="chart_div" style="width: 800px; height: 400px;"></div>

inside of /*.....*/ is the percentiles that I need to show with the data in mysql...but I comented because the chart is not shown when that data don't have /*...*/

here the chart right now..

can you help me with my type of chart?

Best Regards

Andrés Valencia

解决方案

This is the basic framework you will need to make this work:

/*
 * $normal is an array of (edad => peso) key/value pairs
 * $desnutricion is an array of (edad => peso) key/value pairs
 * $desnutricionSevera is an array of (edad => peso) key/value pairs
 * 
 * you can hard-code these or pull them from a database, whatever works for you
 */
$sql = $conn->prepare("SELECT edad, peso FROM ESTATURA WHERE <criteria to select baby>");
$sql->execute();
$data = array(array('Meses', $apellido, 'Normal', 'Desnutricion', 'Desnutricion Severa'));
while($row = $sql->fetch(PDO::FETCH_ASSOC))  {
    $edad = $row['edad'];
    // use (int) to parse the value as an integer
    // or (float) to parse the value as a floating point number
    // use whichever is appropriate
    $edad = (int) preg_replace('/\D/', '', $edad);
    $peso = $row['peso'];
    $peso = (float) $peso;

    $data[] = array($edad, $peso, $normal[$edad], $desnutricion[$edad], $desnutricionSevera[$edad]);
}

Then, in your javascript:

function drawChart() {
    var data = google.visualization.arrayToDataTable(<?php echo json_encode($data); ?>);
    // sort the data by "Meses" to make sure it is in the right order
    data.sort(0);

    var options = {
        title: 'Grafica de Crecimiento de niñas de 0 a 24 meses',
        hAxis: {
            title: 'Meses',
            titleTextStyle: {color: '#333'}
        },
        vAxis: {
            minValue: 0
        },
        series: {
            0: {
                // series options for this babys weight
                type: 'line'
            },
            1: {
                // series options for normal weight
                type: 'area'
            },
            2: {
                // series options for desnutricion
                type: 'area'
            },
            3: {
                // series options for desnutricion severa
                type: 'area'
            }
        }
    };

    var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
    chart.draw(data, options);
}

Give that a try and see if it works for you.

这篇关于如何使增长宝图与mysql + PDO中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆