Skip to content

Instantly share code, notes, and snippets.

@nnnnnoel
Created June 2, 2020 02:36
Show Gist options
  • Save nnnnnoel/89cbe1bd50f18a5cd64204703db52b82 to your computer and use it in GitHub Desktop.
Save nnnnnoel/89cbe1bd50f18a5cd64204703db52b82 to your computer and use it in GitHub Desktop.
Line Chart Formula
const getLineChartD = ({ data, size, width, padding, topSpacing }) => {
const min = Math.min(...data);
const max = Math.max(...data);
const d = data
.map((v, i) => {
return `${i === 0 ? 'M' : 'L'} ${(i * (width - padding * 5)) / data.length},${
size - (v / (max - min)) * size + (topSpacing || 0)
}`;
}).join(' ');
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment