I would like to render a graphic like this :
I thought that Sankey diagram is what is for create diagram like this and I use https://www.npmjs.com/package/chartjs-chart-sankey
But I cannot indicate different start and end width for each flow with Sankey
For each flow, start width and end width is the same. What I need is different width/weight on the same flow between start and end
My try : https://codepen.io/dada17xs/pen/MWdvRbv
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My Website</title>
<link rel="stylesheet" href="./style.css">
<link rel="icon" href="./favicon.ico" type="image/x-icon">
</head>
<body>
<main style="height: 200px; width: 400px;">
<canvas id="myChart" style="width: 300px;"></canvas>
</main>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-chart-sankey"></script>
<script>
const ctx = document.getElementById('myChart');
const colors = {
a: 'red',
b: 'green',
c: 'blue',
d: 'gray'
};
const getColor = (key) => colors[key];
const chart = new Chart(ctx, {
type: 'sankey',
data: {
datasets: [{
label: 'My sankey',
data: [{
from: 'a',
to: 'b',
flow: 10
},
{
from: 'a',
to: 'c',
flow: 5
},
{
from: 'b',
to: 'c',
flow: 10
},
{
from: 'd',
to: 'c',
flow: 7
}
],
colorFrom: (c) => getColor(c.dataset.data[c.dataIndex].from),
colorTo: (c) => getColor(c.dataset.data[c.dataIndex].to),
colorMode: 'gradient', // or 'from' or 'to'
/* optional labels */
labels: {
a: 'Label A',
b: 'Label B',
c: 'Label C',
d: 'Label D'
},
/* optional priority */
priority: {
b: 1,
d: 0
},
/* optional column overrides */
column: {
d: 1
},
size: 'max', // or 'min' if flow overlap is preferred
}]
},
});
</script>
</body>
</html>
How can I create a graphic like this ? And with wich library ?
For more context :
Example : I would like to make this graphic to display data about product and revenue of a company : product A is 10% of sales number (left of the graph above) and make 40% of revenue (right of the graph above), product B si 30% of sales number and make 10% of revenue…