Angular + Canvasjs: Octal literals are not allowed in strict mode

Issue

I am working on full stack development and using Angular, Node/Express and MySQL. I am trying to add a graph in my angular application which will be displayed on the basis of the data available in my database. I have downloaded the sample code available on canvasjs website. Before modifying it to my needs, I have tried to run the sample code and it’s throwing an error.

Here’s the code:

var chart = new CanvasJS.Chart("chartContainer",
{
  title:{
  text: "Projects by their Status"
  },
  axisX: {
    valueFormatString: "MMMM",
    interval: 1,
    intervalType: "month"

  },
  data: [
  {
    type: "stackedColumn",
    legendText: "Completed",
    showInLegend: "true",
    dataPoints: [
    { x: new Date(2012, 01, 1), y: 71 },
    { x: new Date(2012, 02, 1), y: 55},
    { x: new Date(2012, 03, 1), y: 50 },
    { x: new Date(2012, 04, 1), y: 65 },
    { x: new Date(2012, 05, 1), y: 95 }

    ]
  },
    {
    type: "stackedColumn",
    legendText: "snacks",
    showInLegend: "true",
    dataPoints: [
    { x: new Date(2012, 01, 1), y: 71 },
    { x: new Date(2012, 02, 1), y: 55},
    { x: new Date(2012, 03, 1), y: 50 },
    { x: new Date(2012, 04, 1), y: 65 },
    { x: new Date(2012, 05, 1), y: 95 }

    ]
  },
    {
    type: "stackedColumn",
    legendText: "Drinks",
    showInLegend: "true",
    dataPoints: [
    { x: new Date(2012, 01, 1), y: 71 },
    { x: new Date(2012, 02, 1), y: 55},
    { x: new Date(2012, 03, 1), y: 50 },
    { x: new Date(2012, 04, 1), y: 65 },
    { x: new Date(2012, 05, 1), y: 95 }

    ]
  },

    {
    type: "stackedColumn",
    legendText: "dessert",
    showInLegend: "true",
    dataPoints: [
    { x: new Date(2012, 01, 1), y: 61 },
    { x: new Date(2012, 02, 1), y: 75},
    { x: new Date(2012, 03, 1), y: 80 },
    { x: new Date(2012, 04, 1), y: 85 },
    { x: new Date(2012, 05, 1), y: 105 }

    ]
  },
    {
    type: "stackedColumn",
    legendText: "pick-ups",
    showInLegend: "true",
    dataPoints: [
    { x: new Date(2012, 01, 1), y: 20 },
    { x: new Date(2012, 02, 1), y: 35},
    { x: new Date(2012, 03, 1), y: 30 },
    { x: new Date(2012, 04, 1), y: 45 },
    { x: new Date(2012, 05, 1), y: 25 }

    ]
  }

  ]
});

It’s throwing an error:

Octal literals are not allowed in strict mode.
Octal literals are not available when targeting ECMAScript 5 and higher. Use 
the syntax '0o5'.

Solution

In strict mode, octal literals & escape characters are not allowed. You can use one of the standard date-formats in your case.

Answered By – Vishwas R

Answer Checked By – David Goodson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.