提交按钮后立即加载和禁用图表

时间:2018-09-21 07:37:39

标签: javascript charts

我是php,js,MYsql的新手。目前正在使用Chartjs生成图表,而没有针对每个客户的案例。

请找到我下面的代码。

<?php

$conn = mysqli_connect("localhost", "root", "DB", "DB");
$query="select account_name,count(*) as count from case group by name";
$result = mysqli_query($conn, $query);
$json=[];
$json1=[];
while($row = mysqli_fetch_assoc($result) )
{
extract($row);
$json[]= $count;
$json1[]=$account_name;
}
#echo json_encode($json);
#echo "<br>".json_encode($json1);

?>
<Html>
<Head>
<Style>

</style>
<title>Chart Collection</title>
</head>
<Body>
<form id="formID" class="form-horizontal" method="post"
                name="frmCSVImport" >
Start Date:
                <Input type="date" id="date_start" name="date_start">
                <br> <br>
                End Date:
                <Input type="date" id="date_end" name="date_end">
                <button id="run" type="submit" onclick=make_chart() name="run" >Run</button>
                </form>
<div class="mycharts">
<h3>Customer Cases</h3>
<canvas id="myChart"></canvas>
</div>
<br>
<br>
<br>
<div class="chart2">
<br>
<h3>Customer</h3>
<canvas id="myChart2"></canvas>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<Script type="text/javascript">
function make_chart()
{

Chart.defaults.global.defaultFontFamily = "'Roboto', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
Chart.defaults.global.legend.position = 'bottom';
Chart.defaults.global.legend.labels.usePointStyle = true;
Chart.defaults.global.legend.labels.boxWidth = 15;
Chart.defaults.global.tooltips.backgroundColor = '#000';
var ctx = document.getElementById('myChart').getContext('2d');

var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'pie',

    // The data for our dataset
    data: {
            labels:  <?php echo json_encode($json1); ?>,
        datasets: [{
            label: "Customer Case",
            backgroundColor:[   'rgba(255,99,132,1)',
                'rgba(540, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'],
            borderColor:[   'rgba(255,99,132,1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'],
            data: <?php echo json_encode($json); ?>,
        hoverBorderWidth: 20,

        }]
    },

    // Configuration options go here
    options: {
     responsive:false,
      maintainAspectRatio: false,
 scales: {          
        }       
    }
});
var ctx2 = document.getElementById('myChart2').getContext('2d');
var chart = new Chart(ctx2, {
    // The type of chart we want to create
    type: 'bar',

    // The data for our dataset
    data: {
            labels:  <?php echo json_encode($json1); ?>,
        datasets: [{
            label: "Customer Case",
            backgroundColor:[   'rgba(255,99,132,1)',
                'rgba(540, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'],
            borderColor:[   'rgba(255,99,132,1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'],
            data: <?php echo json_encode($json); ?>,
        hoverBorderWidth: 20,

        }]
    },

    // Configuration options go here
    options: {
     responsive:true,
      maintainAspectRatio: true,
 scales: {

        }   
    }
});
}
</script>
<body>
</html>

在提交表单后,图表即被加载,并立即从页面中删除..您能告诉我我在此代码中缺少的信息吗?

预先感谢...

0 个答案:

没有答案