 
(function(){



var series = [{"name":"2021 FEB", "y": 169.0 },{"name":"2021 MAR", "y": 179.0 },{"name":"2021 APR", "y": 177.0 },{"name":"2021 MAY", "y": 166.0 },{"name":"2021 JUN", "y": 167.0 },{"name":"2021 JUL", "y": 178.0 },{"name":"2021 AUG", "y": 179.0 },{"name":"2021 SEP", "y": 173.0 },{"name":"2021 OCT", "y": 166.0 },{"name":"2021 NOV", "y": 175.0 },{"name":"2021 DEC", "y": 165.0 },{"name":"2022 JAN", "y": 180.0 },{"name":"2022 FEB", "y": 176.0 },{"name":"2022 MAR", "y": 179.0 },{"name":"2022 APR", "y": 174.0 },{"name":"2022 MAY", "y": 182.0 },{"name":"2022 JUN", "y": 178.0 },{"name":"2022 JUL", "y": 185.0 },{"name":"2022 AUG", "y": 185.0 },{"name":"2022 SEP", "y": 177.0 },{"name":"2022 OCT", "y": 181.0 },{"name":"2022 NOV", "y": 177.0 },{"name":"2022 DEC", "y": 171.0 },{"name":"2023 JAN", "y": 195.0 },{"name":"2023 FEB", "y": 213.0 },{"name":"2023 MAR", "y": 201.0 },{"name":"2023 APR", "y": 202.0 },{"name":"2023 MAY", "y": 214.0 },{"name":"2023 JUN", "y": 212.0 },{"name":"2023 JUL", "y": 214.0 },{"name":"2023 AUG", "y": 214.0 },{"name":"2023 SEP", "y": 208.0 },{"name":"2023 OCT", "y": 217.0 },{"name":"2023 NOV", "y": 209.0 },{"name":"2023 DEC", "y": 211.0 },{"name":"2024 JAN", "y": 212.0 },{"name":"2024 FEB", "y": 197.0 },{"name":"2024 MAR", "y": 210.0 },{"name":"2024 APR", "y": 206.0 },{"name":"2024 MAY", "y": 203.0 },{"name":"2024 JUN", "y": 205.0 },{"name":"2024 JUL", "y": 203.0 },{"name":"2024 AUG", "y": 202.0 },{"name":"2024 SEP", "y": 194.0 },{"name":"2024 OCT", "y": 202.0 },{"name":"2024 NOV", "y": 194.0 },{"name":"2024 DEC", "y": 200.0 },{"name":"2025 JAN", "y": 203.0 },]

var description = {"title":"RPI: Average Price - Coffee sachets, pack, 70 - 200g eg latte/cappuccino","contact":{"email":"cpi@ons.gov.uk","name":"Consumer Price Inflation team","telephone":"Consumer Price Inflation Enquiries: +44 1633 456900. Consumer Price Inflation recorded message (available after 8am on release day): +44 808 196 1267"},"releaseDate":"2026-04-21T23:00:00.000Z","nextRelease":"20 May 2026","datasetId":"MM23","datasetUri":"/economy/inflationandpriceindices/datasets/consumerpriceindices","cdid":"FV2O","unit":"","preUnit":"","source":"","date":"2025 JAN","number":"203","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: ["2021 FEB","2021 MAR","2021 APR","2021 MAY","2021 JUN","2021 JUL","2021 AUG","2021 SEP","2021 OCT","2021 NOV","2021 DEC","2022 JAN","2022 FEB","2022 MAR","2022 APR","2022 MAY","2022 JUN","2022 JUL","2022 AUG","2022 SEP","2022 OCT","2022 NOV","2022 DEC","2023 JAN","2023 FEB","2023 MAR","2023 APR","2023 MAY","2023 JUN","2023 JUL","2023 AUG","2023 SEP","2023 OCT","2023 NOV","2023 DEC","2024 JAN","2024 FEB","2024 MAR","2024 APR","2024 MAY","2024 JUN","2024 JUL","2024 AUG","2024 SEP","2024 OCT","2024 NOV","2024 DEC","2025 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;


 })()