$(() => {
const markerPath = {
'Original Signal': 'M 0 8 C 2 4 7 4 9.5 8 C 11 12 16 12 18 8 L 18 10 C 16 14 11 14 8.5 10 C 7 6 2 6 0 10 Z',
'Noisy Signal': 'M 18 8 L 12 12 L 7 3 L 0 7.4 L 0 10 L 6 6 L 11 15 L 18 10.6 Z',
};
$('#chart').dxChart({
dataSource,
title: 'Noisy and Original Signals',
commonSeriesSettings: {
argumentField: 'argument',
point: {
visible: false,
},
},
series: [{
valueField: 'originalValue',
name: 'Original Signal',
}, {
valueField: 'value',
name: 'Noisy Signal',
}],
legend: {
verticalAlignment: 'bottom',
horizontalAlignment: 'center',
markerTemplate(item, group) {
const marker = document.createElementNS('http://www.w3.org/2000/svg', 'path');
const background = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
const color = item.series.isVisible() ? item.marker.fill : '#888';
background.setAttribute('fill', color);
background.setAttribute('opacity', 0.3);
background.setAttribute('width', 18);
background.setAttribute('height', 18);
background.setAttribute('x', 0);
background.setAttribute('y', 0);
marker.setAttribute('fill', color);
marker.setAttribute('d', markerPath[item.series.name]);
group.appendChild(marker);
group.appendChild(background);
},
},
onLegendClick(e) {
if (e.target.isVisible()) {
e.target.hide();
} else {
e.target.show();
}
},
});
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script>
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/22.2.6/css/dx.light.css" />
<script src="https://cdn3.devexpress.com/jslib/22.2.6/js/dx.all.js"></script>
<script src="data.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="index.js"></script>
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="chart"></div>
</div>
</body>
</html>
#chart {
height: 440px;
}
function generateData(start, end, step) {
const data = [];
for (let i = start; i < end; i += step) {
const originalValue = Math.sin(i) / i;
data.push({ value: originalValue + ((0.5 - Math.random()) / 10), originalValue, argument: i });
}
return data;
}
const dataSource = generateData(2.5, 12, 0.1);