Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { ChartJSNodeCanvas } = require('chartjs-node-canvas');
- const fs = require("fs");
- const width = 1080; //px
- const height = 540; //px
- const for_chart_labels = ['01.02.2021 Пн/Mon', '02.02.2021 Вт/Tue', '03.02.2021 Ср/Wed', '04.02.2021 Чт/Thu', '05.02.2021 Пт/Fri', '06.02.2021 Сб/Sat', '07.02.2021 Вс/Sun'];
- const for_chart_data = [8706, 2725, 6821, 7602, 8452, 0, 8205];
- const chartJSNodeCanvas = new ChartJSNodeCanvas({ width, height });
- (async () => {
- const configuration = {
- type: "bar",
- data: {
- labels: for_chart_labels,
- datasets: [{
- label: "",
- borderWidth: 2,
- borderColor: [
- "rgb(255, 99, 132)",
- "rgb(54, 162, 235)",
- "rgb(255, 206, 86)",
- "rgb(75, 192, 192)",
- "rgb(153, 102, 255)",
- "rgb(255, 159, 64)",
- "rgb(255, 99, 132)"
- ],
- data: for_chart_data,
- backgroundColor: [
- "rgba(255, 99, 132, 0.2)",
- "rgba(54, 162, 235, 0.2)",
- "rgba(255, 206, 86, 0.2)",
- "rgba(75, 192, 192, 0.2)",
- "rgba(153, 102, 255, 0.2)",
- "rgba(255, 159, 64, 0.2)",
- "rgba(255, 99, 132, 0.2)"
- ]
- }]
- },
- options: {
- legend: {
- display: false
- },
- scales: {
- xAxes: [{
- gridLines: {
- display: false,
- },
- ticks: {
- display: false
- }
- }],
- yAxes: [{
- gridLines: {
- display: false,
- },
- ticks: {
- display: false
- }
- }]
- }
- }};
- const image = await chartJSNodeCanvas.renderToBuffer(configuration);
- fs.writeFile("./hello.png", image, function(error){
- if(error) throw error; // если возникла ошибка
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment