ChartAct / web /Chart.js /scatter /chart_0054_scatter.html
wumumu's picture
Add files using upload-large-folder tool
dae061a verified
Raw History Blame Contribute Delete
3.53 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Center Positioning</title>
<style>
:root {
color-scheme: light;
}
body {
margin: 0;
padding: 20px;
font-family: Segoe UI, Arial, sans-serif;
background: #f5f7fb;
color: #1f2a37;
}
h1 {
margin: 0 0 10px 0;
font-size: 20px;
font-weight: 600;
}
#legend-container {
margin-bottom: 8px;
}
#chart-wrap {
position: relative;
width: min(1100px, 100%);
height: 520px;
background: #ffffff;
border: 1px solid #e2e8f0;
border-radius: 10px;
padding: 12px;
box-sizing: border-box;
}
#chart {
width: 100%;
height: 100%;
}
</style>
<script src="./luxon.min.js"></script>
<script src="./chart.umd.min.js"></script>
<script src="./chartjs-adapter-luxon.umd.min.js"></script>
</head>
<body>
<h1>Center Positioning</h1>
<div id="legend-container"></div>
<div id="chart-wrap">
<canvas id="chart"></canvas>
</div>
<script type="text/plain" data-chart-inline="true">
const DATA_COUNT = 6;
const NUMBER_CFG = {count: DATA_COUNT, min: -100, max: 100};
const data = {
datasets: [
{
label: 'Dataset 1',
data: [{x: -66.11111111, y: 68.52880658}, {x: 9.10665295, y: -72.30281207}, {x: -51.68381344, y: 21.22770919}, {x: -53.42078189, y: -33.59567901}, {x: 35.99451303, y: -49.11865569}, {x: -92.07990398, y: -45.09430727}],
fill: false,
borderColor: Utils.CHART_COLORS.red,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
},
{
label: 'Dataset 2',
data: [{x: -93.12757202, y: -17.74691358}, {x: -27.78635117, y: 75.989369}, {x: -24.37928669, y: -55.17146776}, {x: -43.40020576, y: 50.49897119}, {x: 58.36076818, y: 91.76611797}, {x: -49.96056241, y: 26.65466392}],
fill: false,
borderColor: Utils.CHART_COLORS.blue,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
}
]
};
const config = {
type: 'scatter',
data: data,
options: {
responsive: true,
plugins: {
title: {
display: true,
text: 'Axis Center Positioning'
}
},
scales: {
x: {
min: -100,
max: 100,
},
y: {
min: -100,
max: 100,
}
}
},
};
function forceEnableHoverTooltip(chartConfig) {
if (!chartConfig || typeof chartConfig !== 'object') {
return;
}
if (!chartConfig.options || typeof chartConfig.options !== 'object') {
chartConfig.options = {};
}
const options = chartConfig.options;
if (!options.plugins || typeof options.plugins !== 'object') {
options.plugins = {};
}
const plugins = options.plugins;
if (plugins.tooltip === false) {
plugins.tooltip = {};
}
if (!plugins.tooltip || typeof plugins.tooltip !== 'object') {
plugins.tooltip = {};
}
const hasExternalTooltip = typeof plugins.tooltip.external === 'function';
if (!hasExternalTooltip) {
plugins.tooltip.enabled = true;
}
}
forceEnableHoverTooltip(config);
const sampleCanvas = document.getElementById('chart');
const sampleChart = new Chart(sampleCanvas, config);
</script>
<script src="./chart_0054_scatter.inline01.js"></script>
</body>
</html>