{* Smarty *}

{literal}
<script type="text/javascript">
/**
 * Visualize an HTML table using Highcharts. The top (horizontal) header 
 * is used for series names, and the left (vertical) header is used 
 * for category names. This function is based on jQuery.
 * @param {Object} table The reference to the HTML table to visualize
 * @param {Object} options Highcharts options
 */
Highcharts.visualize = function(table, options) {
  // the categories
  options.xAxis.categories = [];
  $('tbody th', table).each( function(i) {
    options.xAxis.categories.push(this.innerHTML);
  });

  // the data series
  options.series = [];
  $('tr', table).each( function(i) {
    var tr = this;
    $('th, td', tr).each( function(j) {
      if (j > 0) { // skip first column
        if (i == 0) { // get the name and init the series
          options.series[j - 1] = { 
            name: this.innerHTML,
            data: []
          };
        } else { // add values
          options.series[j - 1].data.push(parseFloat(this.innerHTML));
        }
      }
    });
  });

  var chart = new Highcharts.Chart(options);
}

// On document ready, call visualize on the datatable.
$(document).ready(function() {			
  var table = document.getElementById('DemandsReportForOperatorsCharts'),
  options = {
       chart: {
          renderTo: 'DivDemandsContainer',
          defaultSeriesType: 'column'
       },
       title: {
          text: 'Количество заявок по годам'
       },
       xAxis: {
       },
       yAxis: {
          title: {
             text: 'Количество'
          }
       },
       tooltip: {
          formatter: function() {
             return '<b>'+ this.series.name +'</b><br/>'+
                this.y +' '+ this.x.toLowerCase();
          }
       }
    };

  Highcharts.visualize(table, options);
});
</script>
{/literal}

<div id="DivDemandsContainer" style="width: 800px; height: 400px; margin: 0 auto;"></div>
{assign var="VarDatePrev" value="-1"}
{foreach name=Arr key=cid item=val from=$ArrDate}
  {if $smarty.foreach.Arr.first}
<table id="DemandsReportForOperatorsCharts" style="display: none;"><!-- -->
  <thead>
    <tr>
    {foreach name=ArrDemandsClassif key=cidDemandsClassif item=valDemandsClassif from=$ArrDemandsClassif}
      {if $smarty.foreach.ArrDemandsClassif.first}
      <th></th>
      {/if}
      <th>{$valDemandsClassif.demandsclassif_name}</th>
    {/foreach}
    </tr>
  </thead>
  <tbody>
  {/if}
  {if $VarDatePrev neq $val.year_demands_date}
    {if -1 neq $VarDatePrev}
    </tr>
    {/if}
    {assign var="VarDatePrev" value=$val.year_demands_date}
    <tr>
      <th>{$val.year_demands_date}</th>
  {/if}
      <td>{$val.cnt}</td>
{if $smarty.foreach.Arr.last}
  </tbody>
</table>
{/if}
{/foreach}