How to Add Chart in PDF using .NET MVC

90 Views Asked by At

I want to add chart in PDF in .NET MVC. I am using Rotativa PDF for generating pdf but chart.js is not working

I tried using chart.js cdn and other things but not worked for me. I am generating chart using chart.js and canvas from given data


@{
    ViewBag.Title = "MyChartView";
}
<script src="~/Scripts/chart.min.js"></script>

<div style="width: 100%; text-align: center;">
    <canvas id="myChart" width="600" height="400"></canvas>
</div>

<script>
    var ctx = document.getElementById('myChart').getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
            datasets: [{
                label: '# of Votes',
                data: [12, 19, 3, 5, 2, 3],
                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)'
                ],
                borderColor: [
                    'rgba(255, 99, 132, 1)',
                    'rgba(54, 162, 235, 1)',
                    'rgba(255, 206, 86, 1)',
                    'rgba(75, 192, 192, 1)',
                    'rgba(153, 102, 255, 1)',
                    'rgba(255, 159, 64, 1)'
                ],
                borderWidth: 1
            }]
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true
                    }
                }]
            }
        }
    });
</script>


<h2>MyChartView</h2>


0

There are 0 best solutions below