SPC Control Charts in JavaScript

How to make a D3.js-based SPC Control Charts in javascript.


Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.

var Data = {
  type: 'scatter',
  x: [1,2,3,4,5,6,7,8,9],
  y: [4,2,-1,4,-5,-7,0,3,8],
  mode: 'lines+markers',
  name: 'Data',
  showlegend: true,
  hoverinfo: 'all',
  line: {
    color: 'blue',
    width: 2
  },
  marker: {
    color: 'blue',
    size: 8,
    symbol: 'circle'
  }
}

var Viol = {
  type: 'scatter',
  x: [6,9],
  y: [-7,8],
  mode: 'markers',
  name: 'Violation',
  showlegend: true,
  marker: {
    color: 'rgb(255,65,54)',
    line: {width: 3},
    opacity: 0.5,
    size: 12,
    symbol: 'circle-open'
  }
}

var CL = {
  type: 'scatter',
  x: [0.5, 10, null, 0.5, 10],
  y: [-5, -5, null, 5, 5],
  mode: 'lines',
  name: 'LCL/UCL',
  showlegend: true,
  line: {
    color: 'red',
    width: 2,
    dash: 'dash'
  }
}

var Centre = {
  type: 'scatter',
  x: [0.5, 10],
  y: [0, 0],
  mode: 'lines',
  name: 'Centre',
  showlegend: true,
  line: {
    color: 'grey',
    width: 2
  }
}

var data = [Data,Viol,CL,Centre]

var layout = {
  title: {
    text: 'Basic SPC Chart'
  },
  xaxis: {
    zeroline: false
  },
  yaxis: {
    range: [-10,10],
    zeroline: false
  }
}

Plotly.newPlot('myDiv', data,layout);
</script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"var Data = {\n type: 'scatter',\n x: [1,2,3,4,5,6,7,8,9],\n y: [4,2,-1,4,-5,-7,0,3,8],\n mode: 'lines+markers',\n name: 'Data',\n showlegend: true,\n hoverinfo: 'all',\n line: {\n color: 'blue',\n width: 2\n },\n marker: {\n color: 'blue',\n size: 8,\n symbol: 'circle'\n }\n}\n\nvar Viol = {\n type: 'scatter',\n x: [6,9],\n y: [-7,8],\n mode: 'markers',\n name: 'Violation',\n showlegend: true,\n marker: {\n color: 'rgb(255,65,54)',\n line: {width: 3},\n opacity: 0.5,\n size: 12,\n symbol: 'circle-open'\n }\n}\n\nvar CL = {\n type: 'scatter',\n x: [0.5, 10, null, 0.5, 10],\n y: [-5, -5, null, 5, 5],\n mode: 'lines',\n name: 'LCL/UCL',\n showlegend: true,\n line: {\n color: 'red',\n width: 2,\n dash: 'dash'\n }\n}\n\nvar Centre = {\n type: 'scatter',\n x: [0.5, 10],\n y: [0, 0],\n mode: 'lines',\n name: 'Centre',\n showlegend: true,\n line: {\n color: 'grey',\n width: 2\n }\n}\n\nvar data = [Data,Viol,CL,Centre]\n\nvar layout = {\n title: {\n text: 'Basic SPC Chart'\n },\n xaxis: {\n zeroline: false\n },\n yaxis: {\n range: [-10,10],\n zeroline: false\n }\n}\n\nPlotly.newPlot('myDiv', data,layout);\n"}">
var Data = {
  type: 'scatter',
  x: [1,2,3,4,5,6,7,8,9],
  y: [4,2,-1,4,-5,-7,0,3,8],
  mode: 'lines+markers',
  name: 'Data',
  showlegend: true,
  hoverinfo: 'all',
  line: {
    color: 'blue',
    width: 2
  },
  marker: {
    color: 'blue',
    size: 8,
    symbol: 'circle'
  }
}

var Viol = {
  type: 'scatter',
  x: [6,9],
  y: [-7,8],
  mode: 'markers',
  name: 'Violation',
  showlegend: true,
  marker: {
    color: 'rgb(255,65,54)',
    line: {width: 3},
    opacity: 0.5,
    size: 12,
    symbol: 'circle-open'
  }
}

var CL = {
  type: 'scatter',
  x: [0.5, 10, null, 0.5, 10],
  y: [-5, -5, null, 5, 5],
  mode: 'lines',
  name: 'LCL/UCL',
  showlegend: true,
  line: {
    color: 'red',
    width: 2,
    dash: 'dash'
  }
}

var Centre = {
  type: 'scatter',
  x: [0.5, 10],
  y: [0, 0],
  mode: 'lines',
  name: 'Centre',
  showlegend: true,
  line: {
    color: 'grey',
    width: 2
  }
}

var histo = {
  type: 'histogram',
  x: [1,2,3,4,5,6,7,8,9],
  y: [4,2,-1,4,-5,-7,0,3,8],
  name: 'Distribution',
  orientation: 'h',
  marker: {
    color: 'blue',
    line: {
      color: 'white',
      width: 1
    }
  },
  xaxis: 'x2',
  yaxis: 'y2'
}

var data = [Data,Viol,CL,Centre,histo]

// layout
var layout = {
  title: {
    text: 'Basic SPC Chart'
  },
  xaxis: {
    domain: [0, 0.7], // 0 to 70% of width
    zeroline: false
  },
  yaxis: {
    range: [-10,10],
    zeroline: false
  },
  xaxis2: {
    domain: [0.8, 1] // 70 to 100% of width
  },
  yaxis2: {
    anchor: 'x2',
    showticklabels: false
  }
}

Plotly.newPlot('myDiv', data,layout);
</script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"var Data = {\n type: 'scatter',\n x: [1,2,3,4,5,6,7,8,9],\n y: [4,2,-1,4,-5,-7,0,3,8],\n mode: 'lines+markers',\n name: 'Data',\n showlegend: true,\n hoverinfo: 'all',\n line: {\n color: 'blue',\n width: 2\n },\n marker: {\n color: 'blue',\n size: 8,\n symbol: 'circle'\n }\n}\n\nvar Viol = {\n type: 'scatter',\n x: [6,9],\n y: [-7,8],\n mode: 'markers',\n name: 'Violation',\n showlegend: true,\n marker: {\n color: 'rgb(255,65,54)',\n line: {width: 3},\n opacity: 0.5,\n size: 12,\n symbol: 'circle-open'\n }\n}\n\nvar CL = {\n type: 'scatter',\n x: [0.5, 10, null, 0.5, 10],\n y: [-5, -5, null, 5, 5],\n mode: 'lines',\n name: 'LCL/UCL',\n showlegend: true,\n line: {\n color: 'red',\n width: 2,\n dash: 'dash'\n }\n}\n\nvar Centre = {\n type: 'scatter',\n x: [0.5, 10],\n y: [0, 0],\n mode: 'lines',\n name: 'Centre',\n showlegend: true,\n line: {\n color: 'grey',\n width: 2\n }\n}\n\nvar histo = {\n type: 'histogram',\n x: [1,2,3,4,5,6,7,8,9],\n y: [4,2,-1,4,-5,-7,0,3,8],\n name: 'Distribution',\n orientation: 'h',\n marker: {\n color: 'blue',\n line: {\n color: 'white',\n width: 1\n }\n },\n xaxis: 'x2',\n yaxis: 'y2'\n}\n\nvar data = [Data,Viol,CL,Centre,histo]\n\n// layout\nvar layout = {\n title: {\n text: 'Basic SPC Chart'\n },\n xaxis: {\n domain: [0, 0.7], // 0 to 70% of width\n zeroline: false\n },\n yaxis: {\n range: [-10,10],\n zeroline: false\n },\n xaxis2: {\n domain: [0.8, 1] // 70 to 100% of width\n },\n yaxis2: {\n anchor: 'x2',\n showticklabels: false\n }\n}\n\nPlotly.newPlot('myDiv', data,layout);\n"}">