使用PHP&创建图表JavaScript的

时间:2018-04-16 14:58:41

标签: javascript php charts

我是PHP&的新手。 Javascript因此可能有很多新手错误 - 我的目标是从DB(dimension1等)中获取4个答案并在PHP中分配值。然后将这些PHP值传递给JS并将其插入图表中以相应地显示结果。目前的代码没有显示任何内容 - 我并不特别担心此时的最佳做法,只是渴望有所作为。我们欢迎所有的建议!

<?php

    $dbQuery = $db->prepare("select dimension1, dimension2, dimension3, dimension4 FROM indexLearningStyle WHERE studentNumber = '".$currentUser."'");
    $dbQuery-> execute();

    while ($dbRow = $dbQuery->fetch (PDO::FETCH_ASSOC)) {
    $dimension1 = $dbRow["dimension1"];
    $dimension2 = $dbRow["dimension2"];
    $dimension3 = $dbRow["dimension3"];
    $dimension4 = $dbRow["dimension4"]; 

    }

    if  ($dimension1 = "Strongly Active"){
        $chartDimension1 = 0;

    }
    elseif ($dimension1 = "Moderately Active") {
        $chartDimension1 = 0.16;

    }
    elseif ($dimension1 = "Mildly Active") {
        $chartDimension1 = 0.32;

    }
    elseif ($dimension1 = "Strongly Reflective") {
        $chartDimension1 = 1.0;

    }
    elseif ($dimension1 = "Moderately Reflective") {
        $chartDimension1 = 0.84;

    }
    elseif ($dimension1 = "Mildly Reflective") {
        $chartDimension1 = 0.68;

    }

    if  ($dimension2 = "Strongly Sensing"){
        $chartDimension2 = 0;

    }
    elseif ($dimension2 = "Moderately Sensing") {
        $chartDimension2 = 0.16;

    }
    elseif ($dimension2 = "Mildly Sensing") {
        $chartDimension2 = 0.32;

    }
    elseif ($dimension2 = "Strongly Intuitive") {
        $chartDimension2 = 1.0;

    }
    elseif ($dimension2 = "Moderately Intuitive") {
        $chartDimension2 = 0.84;

    }
    elseif ($dimension2 = "Mildly Intuitive") {
        $chartDimension2 = 0.68;

    }

    if  ($dimension3 = "Strongly Visual"){
        $chartDimension3 = 0;

    }
    elseif ($dimension3 = "Moderately Visual") {
        $chartDimension3 = 0.16;

    }
    elseif ($dimension3 = "Mildly Visual") {
        $chartDimension3 = 0.32;

    }
    elseif ($dimension3 = "Strongly Verbal") {
        $chartDimension3 = 1.0;

    }
    elseif ($dimension3 = "Moderately Verbal") {
        $chartDimension3 = 0.84;

    }
    elseif ($dimension3 = "Mildly Verbal") {
        $chartDimension3 = 0.68;

    }
    if  ($dimension4 = "Strongly Sequential"){
        $chartDimension4 = 0;

    }
    elseif ($dimension4 = "Moderately Sequential") {
        $chartDimension4 = 0.16;

    }
    elseif ($dimension4 = "Mildly Sequential") {
        $chartDimension4 = 0.32;

    }
    elseif ($dimension4 = "Strongly Global") {
        $chartDimension4 = 1.0;

    }
    elseif ($dimension4 = "Moderately Global") {
        $chartDimension4 = 0.84;

    }
    elseif ($dimension4 = "Mildly Global") {
        $chartDimension4 = 0.68;

    }

 ?>
 </body>

 <body class="">

 <br><br>
        <div id="studentILS">
        </div>
 </div>
 <br><br><br>


<!-- scripts -->
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script src="cssBipolarChart.js"></script>

<script>

    var chartDimension1 = <?php $chartDimension1 ?>;
    var chartDimension2 = <?php $chartDimension2 ?>;
    var chartDimension3 = <?php $chartDimension3 ?>;
    var chartDimension4 = <?php $chartDimension4 ?>;

    var studentResults = [
        ["Active", "Reflective", <?php echo $chartDimension1; ?>],
        ["Sensing", "Intuitive", <?php echo $chartDimension2; ?>],
        ["Visual", "Verbal", <?php echo $chartDimension3; ?>],
        ["Sequential", "Global", <?php echo $chartDimension4; ?>],
        //for example:["Sequential", "Global", 0.84],
        //["Sequential", "Global", 1.0]
    ]

    $(document).ready(function() {
        $("#studentILS").drawCSSBipolarChart({
            data: studentResults,
            bipolar: true
        })
    })
</script>

0 个答案:

没有答案