 
(function(){



var series = [{"name":"2014 JAN", "y": null },{"name":"2014 FEB", "y": null },{"name":"2014 MAR", "y": null },{"name":"2014 APR", "y": null },{"name":"2014 MAY", "y": null },{"name":"2014 JUN", "y": null },{"name":"2014 JUL", "y": null },{"name":"2014 AUG", "y": null },{"name":"2014 SEP", "y": null },{"name":"2014 OCT", "y": null },{"name":"2014 NOV", "y": null },{"name":"2014 DEC", "y": null },{"name":"2015 JAN", "y": null },{"name":"2015 FEB", "y": null },{"name":"2015 MAR", "y": null },{"name":"2015 APR", "y": null },{"name":"2015 MAY", "y": null },{"name":"2015 JUN", "y": null },{"name":"2015 JUL", "y": null },{"name":"2015 AUG", "y": null },{"name":"2015 SEP", "y": null },{"name":"2015 OCT", "y": null },{"name":"2015 NOV", "y": null },{"name":"2015 DEC", "y": null },{"name":"2016 JAN", "y": null },{"name":"2016 FEB", "y": 107.0 },{"name":"2016 MAR", "y": 106.6 },{"name":"2016 APR", "y": 107.9 },{"name":"2016 MAY", "y": 107.1 },{"name":"2016 JUN", "y": 107.6 },{"name":"2016 JUL", "y": 106.1 },{"name":"2016 AUG", "y": 106.9 },{"name":"2016 SEP", "y": 106.1 },{"name":"2016 OCT", "y": 107.2 },{"name":"2016 NOV", "y": 106.7 },{"name":"2016 DEC", "y": 107.4 },{"name":"2017 JAN", "y": 107.6 },{"name":"2017 FEB", "y": 107.6 },{"name":"2017 MAR", "y": 108.8 },{"name":"2017 APR", "y": 106.8 },{"name":"2017 MAY", "y": 109.1 },{"name":"2017 JUN", "y": 109.1 },{"name":"2017 JUL", "y": 108.1 },{"name":"2017 AUG", "y": 108.1 },{"name":"2017 SEP", "y": 106.9 },{"name":"2017 OCT", "y": 105.9 },{"name":"2017 NOV", "y": 105.0 },{"name":"2017 DEC", "y": 106.4 },{"name":"2018 JAN", "y": 105.0 },]

var description = {"title":"1072190000: Other Dry or Preserved Bbakers' Wares","contact":{"email":"ppi@ons.gov.uk","name":"Martina Portanti","telephone":"+44 (0) 1633 456907 "},"releaseDate":"2018-02-13T00:00:00.000Z","nextRelease":"20 March 2018 ","datasetId":"MM22","datasetUri":"/economy/inflationandpriceindices/datasets/producerpriceindex","cdid":"K2VY","unit":"","preUnit":"","source":"","date":"2018 JAN","number":"105.0","sampleSize":"0"};
var linechart = {
   chart: {
     type: 'line',
     marginRight: 16,
    
    events: {
        load: function () {
            var chart = this,
                yAxis = chart.yAxis[0],
                tp = yAxis.tickPositions,
                firstLabel = yAxis.ticks[tp[0]].label.getBBox().width,
                lastLabel = yAxis.ticks[tp[tp.length - 1]].label.getBBox().width,
                bb = yAxis.axisTitle.getBBox();
            yAxis.update({
                title: {
                offset: -bb.width + (firstLabel > lastLabel ? firstLabel : lastLabel)
            }
            });
        }
    }
   },
   colors: ['#007dc3', '#409ed2', '#7fbee1', '#007dc3', '#409ed2', '#7fbee1'],

   title: {
     text: description.title
   },
   subtitle: {
     text: 'Source: ' + description.source,
     floating: true,
     align: 'right',
     x: 0,
     verticalAlign: 'bottom',
     y: 10
   },
   navigation: {
     buttonOptions: {
       enabled: false
     }
   },
   xAxis: {
     categories: ["2014 JAN","2014 FEB","2014 MAR","2014 APR","2014 MAY","2014 JUN","2014 JUL","2014 AUG","2014 SEP","2014 OCT","2014 NOV","2014 DEC","2015 JAN","2015 FEB","2015 MAR","2015 APR","2015 MAY","2015 JUN","2015 JUL","2015 AUG","2015 SEP","2015 OCT","2015 NOV","2015 DEC","2016 JAN","2016 FEB","2016 MAR","2016 APR","2016 MAY","2016 JUN","2016 JUL","2016 AUG","2016 SEP","2016 OCT","2016 NOV","2016 DEC","2017 JAN","2017 FEB","2017 MAR","2017 APR","2017 MAY","2017 JUN","2017 JUL","2017 AUG","2017 SEP","2017 OCT","2017 NOV","2017 DEC","2018 JAN",],
      tickPositioner: function () {
       var positions = [];
       var increment = Math.ceil(((this.dataMax) - (this.dataMin)) / 16);
       var tick = Math.floor(this.dataMin);
       for (tick; tick < this.dataMax; tick += increment) {
         positions.push(tick);
       }
       //prevent last tick label overlap the last data in the array if too close
       var diff = tick - this.dataMax;
       if(diff >= (increment /2) ) {
        var deleted = positions.pop();
       }

       positions.push(this.dataMax);
       return positions;
     },
     labels: {
        formatter: function() {
          var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
          var response = '';
          if (w < 768) {
            if (this.isFirst) {
              count = 0;
            }
            if (count % 4 === 0 || this.isLast) {
              response = this.value;
            }
            count++;
          } else {
            response = this.value;
          }
          return response;
        }
     },
     tickmarkPlacement: 'on'
   },
   yAxis: {
     title: {
        text: " " + " ",
       align: 'high',
       rotation: 360,
       x: -15,
       y: -10
     },
    labels: {
      format: '{value:,f}'
    }
   },

   credits: {
     enabled: false
   },

    annotationsOptions: {
        enabledButtons: false
    },

   plotOptions: {
     series: {
       turboThreshold:0,
       shadow: false,
       states: {
         hover: {
           enabled: true,
           shadow: false,
           lineWidth: 3,
           lineWidthPlus: 0,
           marker: {
             height: 0,
             width: 0,
             halo: false,
             enabled: true,
             fillColor: null,
             radiusPlus: null,
             lineWidth: 3,
             lineWidthPlus: 0
           }
         }
       }
     }
   },
   tooltip: {
     shared: true,
     width: '150px',
     crosshairs: {
       width: 2,
       color: '#f37121'
     },
     positioner: function(labelWidth, labelHeight, point) {
       var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
       var points = {
         x: 30,
         y: 42
       };
       var tooltipX, tooltipY;
       var chart = Highcharts.charts[Highcharts.charts.length - 1];
       if (w > 768) {

         if (point.plotX + labelWidth > chart.plotWidth) {
           tooltipX = point.plotX + chart.plotLeft - labelWidth - 20;
           $("#custom-tooltip").removeClass('tooltip-left');
         } else {
           tooltipX = point.plotX + chart.plotLeft + 20;
           $("#custom-tooltip").removeClass('tooltip-right');
         }

         tooltipY = 50;
         points = {
           x: tooltipX,
           y: tooltipY
         };
       } else {
         $("#custom-tooltip").removeClass('tooltip-left');
         $("#custom-tooltip").removeClass('tooltip-right');
       }

       return points;
     },

     formatter: function() {
       var id1 = '<div id="custom-tooltip" class="tooltip-left tooltip-right">';
       var block = id1 + "<div class='sidebar' >";
       var title = '<b class="title">' + this.points[0].key + ': </b>';
       var symbol = ['<div class="circle">●</div>', '<div class="square">■</div>', '<div class="diamond">♦</div>', '<div class="triangle">▲</div>', '<div class="triangle">▼</div>'];

       var content = block;

       // symbols
       $.each(this.points, function(i, val) {
         content += symbol[i];
       });

       content += "<br/></div>";
       content += "<div class='maintext maintext__fixed-width'>";
       content += title;

       // series names and values
       $.each(this.points, function(i, val) {
         content += '<div class="tiptext">' + val.point.series.chart.series[i].name + "<br/><b>Value: " + val.point.series.chart.series[i].options.preUnit + numberWithCommas(val.y) + " " + val.point.series.chart.series[i].options.unit + '</b></div>';
       });
       content += "</div>";
       return content;
     },

     backgroundColor: 'rgba(255, 255, 255, 0)',
     borderWidth: 0,
     borderColor: 'rgba(255, 255, 255, 0)',
     shadow: false,
     useHTML: true

   },
   series: [{
     name: description.title,
     id: description.id,
     unit: description.unit,
     preUnit: description.preUnit,
     data: series,
     marker: {
       enabled:true,
       radius:2,
       symbol: "circle",
       states: {
         hover: {
           fillColor: '#007dc3',
           radiusPlus: 0,
           lineWidthPlus: 0
         }
       }
     },
     dashStyle: 'Solid'
   }]
 };

if(!description.isIndex) {
  var min;
  for(i = 0; i<series.length; i++) {
   min = min ? Math.min(min, series[i].y) : series[i].y;
  }
       
  if(min > 0) {
   linechart.yAxis.min = 0;
  } else {
   linechart.yAxis.min = min - 1;
  }

 };


    function numberWithCommas(number) {
    var parts = number.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
    }

window.linechart = linechart;
return linechart;


 })()