-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart-js_linha.php
124 lines (92 loc) · 2.96 KB
/
chart-js_linha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
include 'conexao/conexao.php';
$sql = "SELECT mes_cliente, SUM(quantidade) AS soma FROM clientes INNER JOIN meses ON mes_cliente = meses.mes GROUP BY mes_cliente ORDER BY meses.id_mes";
$buscar = mysqli_query($conexao,$sql);
#chart.js - Preparando valores#
$mes = '';
$quantidade = '';
while ($dados = mysqli_fetch_array($buscar)) {
$mes = $mes . '"' . $dados['mes_cliente'] . '",';
$quantidade = $quantidade . '"' . $dados['soma'] . '",';
$mes = trim($mes); #tira os espaços da variável
$quantidade = trim($quantidade);
}
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.sombra {
-webkit-box-shadow: 6px 9px 7px 0px rgba(176,176,176,0.75);
-moz-box-shadow: 6px 9px 7px 0px rgba(176,176,176,0.75);
box-shadow: 6px 9px 7px 0px rgba(176,176,176,0.75);
}
</style>
<title></title>
<!-- CDN do Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- CDN do Chart.js -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
</head>
<body>
<!-- https://www.colourlovers.com/ -->
<div class="container" style="background-color: #F3F3F3;margin-top: 20px;">
<canvas style="padding:30px" id="linha" class="sombra"></canvas>
</div>
<script type="text/javascript">
var ctx = document.getElementById('linha').getContext('2d');
var myLineChart = new Chart(ctx, {
type: 'line',
data: {
labels:[<?php echo $mes; ?>],
datasets:
[{
label:'quantidade',
data:[<?php echo $quantidade; ?>],
backgroundColor: 'transparent',
borderColor: '#0000FF',
borderWidth: 3
},
]
},
options: {
legend: {
labels: {
fontColor: "black",
fontSize: 18
}
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Meses',
fontColor:'#000',
fontSize:16
},
ticks: {
fontColor: "black",
fontSize: 20
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Quantidade',
fontColor: '#000',
fontSize:16
},
ticks: {
fontColor: "black",
fontSize: 20
}
}]
}
}
});
</script>
<!-- https://expanssiva.com.br/pg/tabela-de-cores-html-hexadecimal-e-rgb -->
</body>
</html>