<?php if ($block->isShowChart()): ?>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

<script type="text/javascript">
    function drawChart() {
        var d = [];
        d.push(['datetime', 'Total Number of RMAs']);

        <?php foreach ($block->getCollection() as $row): ?>
        d.push(['<?php echo date('d M, Y', strtotime($row->getData('created_at'))) ?>', <?php echo intval($row->getData('total_rma_cnt')) ?>]);
        <?php endforeach ?>

        var data = google.visualization.arrayToDataTable(d);

        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));

        var options = {
            chartArea: {
                width: '100%',
                height: '70%'
            },
            
            bar: {
                groupWidth: '95%'
            },

            bars: 'vertical',

            colors: ["#2fd75b", "#ff7e0e", "#52c4ff", "#c7b700", "#aaeeee", "#ff0066", "#eeaaee", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
            
            fontSize: '11',

            legend: {
                position: 'bottom',
                alignment: 'center',
                textStyle: {
                    color    : '#aaaaaa',
                    fontSize : '11'
                }
            },
            hAxis: {
                textStyle: {
                    color    : '#aaaaaa',
                    fontSize : '11'
                },
                slantedText: false,
                maxAlternation: 1
            },
            vAxis: {
                textPosition: 'in',
                baselineColor: '#dddddd',
                gridlines: {
                    color: '#f0f0f0'
                },
                textStyle: {
                    color    : '#aaaaaa'
                }
            }
        }

        google.visualization.events.addListener(chart, 'ready', function () {
            export_link.href = chart.getImageURI();
        });

        var view = new google.visualization.DataView(data);
        
        chart.draw(view, options);
    }

    google.load("visualization", '1.1', {packages:['corechart'], 'language': 'en'});
    google.setOnLoadCallback(drawChart);
</script>

<a id="export_link" target="_blank" style="float:right; z-index: 10000;position:relative;">Save chart as an image</a>
<div id="chart_div" style="widht: 100%; height: 400px;"></div>
<?php endif;?>