score:0

david, this worked for me. are you sure you are passing the labels correctly on render (try date: datearray instead of date: (datearray)). i didn't create a render function for this page so hard coded the labels and data arrays:

        script.
            var labels = ['2022-05-01','2022-05-02','2022-05-03','2022-05-04','2022-05-05',]
            var data = {
                labels: labels,
                datasets: [{
                label: 'my first dataset',
                backgroundcolor: 'rgb(255, 99, 132)',
                bordercolor: 'rgb(255, 99, 132)',
                data: ['4.00', '5.50', '3.00', '1.75', null],
                }]
            };
            var config = {type: 'line',data: data,options: {}};
            var mychart = new chart(document.getelementbyid("mychart"),config);

score:0

if i hardcode the labels in:

const xlabels = [#{date}]

instead of importing from page render, everything works fine. it's exactly that the point. the console.log of datearray is perfectly as i would like to be in the xlabels, while once imported the quotes disappear

console.log(datearray); // ['2022-05-01','2022-05-02','2022-05-03','2022-05-04','2022-05-05']
const xlabels = [#{date}]; // [2022-05-01,2022-05-02,2022-05-03,2022-05-04,2022-05-05]

score:0

not best solution, but it works.... async function getdata()

        var xlabel = '#{date}';
        var xlabel = xlabel.replace(/"/g, '"'); 
        alert(xlabel);
        var xlabel = xlabel.split(",");
        alert(xlabel);



        for(i = 0; i < xlabel.length; i += 1){
         xlabel[i] = xlabel[i];
         //alert(numarray[i]);
         xlabels.push(xlabel[i]);
        }

Related Query

More Query from same tag