Skip to content

Instantly share code, notes, and snippets.

@engalar
Last active November 5, 2022 06:10
Show Gist options
  • Save engalar/9ad006d7e0899618256096cef6ac07a3 to your computer and use it in GitHub Desktop.
Save engalar/9ad006d7e0899618256096cef6ac07a3 to your computer and use it in GitHub Desktop.
plotly distribute chart
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="myDiv"></div>
<body>
// https://codepen.io/engalar/pen/yLjQgzV?editors=0110
function markline(v, color, name, start, end) {
const result = {
type: "scatter",
x: [start, end],
y: [v, v],
mode: "lines",
name,
line: {
color
//width: 2,
//dash: "dash"
}
};
return result;
}
const his = {
xaxis: "x",
yaxis: "y",
x: [1667417267490, 1667517267490, 1667617267490],
y: [2.0, 5.0, -3.0],
//text: 'xxx',
customdata: [
{ order: 11, lotno: "1234", batch: "batch1" },
{ order: 22, lotno: "1234", batch: "batch1" },
{ order: 33, lotno: "1234", batch: "batch1" }
],
line: {
width: 2,
color: "#4c9ab4"
},
name: "测量值",
showlegend: false,
mode: "lines+markers",
hovertemplate:
"<b>Sort number</b>:<br><b>Measurements</b>: %{y}<br><br><i>Insp.order</i>: %{customdata.order}<br><i>Lot no</i>: %{customdata.lotno}<br><i>Batch no</i>: %{customdata.batch}<br><i>Acq.date %{x}</i>:"
};
var data = [
his,
markline(5, "#ed7c7c", "Upper TL(CC1)", 1667417267490, 1667617267490),
markline(2, "#eb6969", "Upper CL(CC1)", 1667417267490, 1667617267490),
markline(1, "#fed66a", "Upper WL(CC1)", 1667417267490, 1667617267490),
markline(-2, "#8cd188", "Process Mean Value", 1667417267490, 1667617267490),
markline(-3, "#fedf8d", "Lower WL(CC1)", 1667417267490, 1667617267490),
markline(-4, "#ee8383", "Lower CL(CC1)", 1667417267490, 1667617267490),
markline(-5, "#e95e5e", "Lower TL(CC1)", 1667417267490, 1667617267490)
];
var layout = {
title: "测量值趋势图",
autosize: true,
xaxis: {
type: "date",
title: "时间",
tickson: "boundaries",
showline: true,
showgrid: false,
rangeselector: {},
rangeslider: {}
},
yaxis: {
title: "测量值",
zeroline: false,
ticksuffix: "%%",
spikemode: "toaxis+across+marker",
showline: true,
showgrid: false
}
};
var config = { responsive: true };
Plotly.plot("myDiv", data, layout, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment