dsebywql016137 2019-08-02 16:22
浏览 24

显示图标签

I am plotting a graph using two data x axis is date and y axis is amount. I am able to display graph without any issue but I trying to display two things and I described it in my expectation below but I am not sure its achievable or not.

Sample Data

2019-01-01---10
2019-02-01---20
2019-03-01---30

Code

<?Php

    $dbhost = '';
    $dbname = '';  
    $dbuser = '';                  
    $dbpass = ''; 


    try{

        $dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
        $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    }catch(PDOException $ex){

        die($ex->getMessage());
    }
    $stmt=$dbcon->prepare("select testdate,balance from test order by testdate");
    $stmt->execute();
    $json= [];
    $json2= [];
    while ($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
        extract($row);
        $json[]= $testdate;
        $json2[]= (int)$balance;
    }
?>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
    <title>Test</title>
</head>
<body>
    <h1>Mortgage Payment</h1>
<div style="width: 1400px; height: 900px;">
<canvas id="myChart"></canvas>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<script type="text/javascript">
    var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'line',


   axisY: {
        title: "Price in USD",
        titleFontSize: 24,
        prefix: "$"
    },


    // The data for our dataset
    data: {
        labels: <?php echo json_encode($json); ?>,
        datasets: [{
            label: "Amount in Dollars ($)  ",

            backgroundColor: '#75A58C',
            borderColor: 'BLACK',


            data: <?php echo json_encode($json2); ?>,
        }]
    },

    // Configuration options go here
    options: {}

});

</script>
</body>
</html>

Expectation

I am expecting two results from this graph

1) Display y axis value in the graph only for the current month.
2) Data will be for every month for the next two years. If this data is populated then background color should be different and the remaining months the background color should be different.
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题