Can you please tell me how to set the gradient in the chart?

var ctx = document.getElementById('myChart'); var myChart = new Chart(ctx, { type: 'doughnut', data: { labels: ['Онлайн', 'Офлайн'], datasets: [{ label: '# of Votes', data: [2, 2], backgroundColor: [ '#62b547', '#7e4be8' ], borderColor: [ '#62b547', '#7e4be8' ], borderWidth: 0 }] }, options: { legend: { display: false, scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } } }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script> <canvas id="myChart"></canvas> 

    1 answer 1

    The gradient is set like this: background: linear-gradient(45deg, #fff 0%, #000 50%);

    But here you need to set the background-image and not the background color