-2
Well, I took a chart of a template that I use, it’s mentioning the attribute canvas
with an ID, I found these ID in a js file (main.js), and changed the values, to change the graph, but it hasn’t changed...
I do not understand anything of JS, if anyone can help me, I will be grateful.
Graphics in HTML:
<!-- GRÁFICOS-->
<div class="col-lg-6">
<div class="au-card m-b-30">
<div class="au-card-inner">
<h3 class="title-2 m-b-40"></h3>
<canvas id="barChart"></canvas>
</div>
</div>
</div>
<!-- END GRÁFICOS-->
Main.js:
(function ($) {
// USE STRICT
"use strict";
try {
//bar chart
var ctx = document.getElementById("barChart");
if (ctx) {
ctx.height = 200;
var myChart = new Chart(ctx, {
type: 'bar',
defaultFontFamily: 'Poppins',
data: {
labels: ["2014", "2015", "2016", "2017", "2018", "2019", "2020"],
datasets: [
{
label: "Pacientes",
data: [35, 44, 47, 79, 120, 145, 70],
borderColor: "rgba(0, 123, 255, 0.9)",
borderWidth: "0",
backgroundColor: "rgba(0, 123, 255, 0.5)",
fontFamily: "Poppins"
},
{
label: "Funcionarios",
data: [20, 22, 30, 33, 36, 50, 40],
borderColor: "rgba(0,0,0,0.09)",
borderWidth: "0",
backgroundColor: "rgba(0,0,0,0.07)",
fontFamily: "Poppins"
}
]
},
options: {
legend: {
position: 'top',
labels: {
fontFamily: 'Poppins'
}
},
scales: {
xAxes: [{
ticks: {
fontFamily: "Poppins"
}
}],
yAxes: [{
ticks: {
beginAtZero: true,
fontFamily: "Poppins"
}
}]
}
}
});
}
} catch (error) {
console.log(error);
}
Oops, thanks for the answer, it’s that lib even apparently, I’m new in this area. So, the name Patients is not appearing, the graph does not change, what can I be doing wrong? And how can I be in the wrong table if it is showing
barChart
?– Samuel Verissimo
@Samuelverissimo reply edited above
– Rafael Balmant
I even put on the same page this documentation of yours, however, has not been displayed... I wonder what it is?
– Samuel Verissimo
There may be several factors that for a chunk of code cannot be verified, I advise you to check the dependencies (installed packages), however, you need to know a little how the package manager works (npm, npx, Yarn) installed in your app...
– Rafael Balmant
Thanks for trying to help me Rafael, it made me go research and try to understand a little bit about. For some reason when I redirect to some script to load the graph, it doesn’t work. I left it with HTML, and I also wasn’t importing the library apparently... Charts.js CDN
– Samuel Verissimo