gemini86 / node-red-contrib-chart-image

2 stars 3 forks source link

Horizontal Bar chart do not start at 0 #22

Closed Yusseiin closed 1 year ago

Yusseiin commented 2 years ago

Hi, i am trying to create an horizontal bar chart, but i wont start from 0, it seems that the "beginAtZero" options does not work. Someone has some ideas?

test . [{"id":"72727b941496bdbe","type":"function","z":"4b95dee7dc7e4ae9","name":"Horizontal example","func":"const labels = [\n 'Gen',\n 'Feb',\n 'Mar',\n 'Apr',\n 'Mag',\n 'Giu',\n 'Lug'\n ];\nconst data = {\n labels: labels,\n datasets: [{\n label: 'My First Dataset',\n data: [65, 59, 80, 81, 56, 55, 40],\n fill: false,\n backgroundColor: [\n 'rgba(255, 99, 132, 0.2)',\n 'rgba(255, 159, 64, 0.2)',\n 'rgba(255, 205, 86, 0.2)',\n 'rgba(75, 192, 192, 0.2)',\n 'rgba(54, 162, 235, 0.2)',\n 'rgba(153, 102, 255, 0.2)',\n 'rgba(114, 115, 113, 0.8)'\n ],\n borderColor: [\n 'rgb(255, 99, 132)',\n 'rgb(255, 159, 64)',\n 'rgb(255, 205, 86)',\n 'rgb(75, 192, 192)',\n 'rgb(54, 162, 235)',\n 'rgb(153, 102, 255)',\n 'rgb(153, 102, 255)'\n ],\n borderWidth: 1\n }]\n};\n\nconst options = {\n plugins: {\n datalabels: {\n display:false\n }\n },\n chartArea: {\n backgroundColor: 'white'\n },\n scales: {\n yAxes: [{\n \n minBarLength: 2,\n beginAtZero: true,\n gridLines: {\n offsetGridLines: true,\n beginAtZero: true\n }\n }]\n }\n};\n \nvar myDoughnutChart = {\n type: 'horizontalBar',\n options: options,\n data: data\n \n};\n\n\n\nmsg.payload = myDoughnutChart;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":320,"wires":[["79db95e5e7caea64"]]}]

gemini86 commented 1 year ago

Here are the needed corrections to your example node:

[{"id":"72727b941496bdbe","type":"function","z":"df36d1113fdcc60e","name":"Horizontal example","func":"const labels = [\n    'Gen',\n    'Feb',\n    'Mar',\n    'Apr',\n    'Mag',\n    'Giu',\n    'Lug'\n];\nconst data = {\n    labels: labels,\n    datasets: [{\n        label: 'My First Dataset',\n        data: [65, 59, 80, 81, 56, 55, 40],\n        fill: false,\n        backgroundColor: [\n            'rgba(255, 99, 132, 0.2)',\n            'rgba(255, 159, 64, 0.2)',\n            'rgba(255, 205, 86, 0.2)',\n            'rgba(75, 192, 192, 0.2)',\n            'rgba(54, 162, 235, 0.2)',\n            'rgba(153, 102, 255, 0.2)',\n            'rgba(114, 115, 113, 0.8)'\n        ],\n        borderColor: [\n            'rgb(255, 99, 132)',\n            'rgb(255, 159, 64)',\n            'rgb(255, 205, 86)',\n            'rgb(75, 192, 192)',\n            'rgb(54, 162, 235)',\n            'rgb(153, 102, 255)',\n            'rgb(153, 102, 255)'\n        ],\n        borderWidth: 1\n    }]\n};\n\nconst options = {\n    plugins: {\n        datalabels: {\n            display: false\n        }\n    },\n    chartArea: {\n        backgroundColor: 'white'\n    },\n    scales: {\n        xAxes: [{\n            gridLines: {\n                offsetGridLines: true,\n                beginAtZero: true\n            },\n            minBarLength: 2,\n            ticks: {\n                beginAtZero: true,\n            },\n        }]\n    }\n};\n\nvar myDoughnutChart = {\n    type: 'horizontalBar',\n    options: options,\n    data: data\n\n};\n\n\n\nmsg.payload = myDoughnutChart;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":160,"wires":[["b030e267bc5e865e"]]}]