I
I
Ilya Loopashko2021-05-24 07:37:52
Laravel
Ilya Loopashko, 2021-05-24 07:37:52

How to pass value from pusher to chart?

Kind everyone. How can I pass the value that I send through the Debug console to insert it into the chart?

For example, I pass the array [1,2,3,4] and how to add to the digram in data: []?

<script>

    Pusher.logToConsole = true;

    var pusher = new Pusher('121212121', {
        cluster: 'eu'
    });

<canvas id="myChart"></canvas>

    <script>
        let ctx = document.getElementById("myChart");
                let myChart = new Chart(ctx, {
                    type: 'bar',
                    data: {
                        labels: [],
                        datasets: [{
                            label: '# of Users',
                            data: [],
                            borderWidth: 1
                        }]
                    },
                    options: {
                        scales: {
                            yAxes: [{
                                ticks: {
                                    beginAtZero:true
                                }
                            }]
                        }
                    }
                });

                var channel = pusher.subscribe('my-channel');
                channel.bind('my-event', function(data) {
                    console.log(data);
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question