Skip to content

Instantly share code, notes, and snippets.

@kristw
Last active July 24, 2020 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristw/517067ddf0535e063d9481f733ca52a3 to your computer and use it in GitHub Desktop.
Save kristw/517067ddf0535e063d9481f733ca52a3 to your computer and use it in GitHub Desktop.
blog example: vx
function BarChart() {
const xScale = scaleBand({ rangeRound: [0, xMax], domain: data.map(d => d.letter) });
const yScale = scaleLinear({ rangeRound: [yMax, 0], domain: [0, Math.max(...data.map(d => d.frequency))] });
return (<svg width={width} height={height}>
{data.map(d => {
const barHeight = yMax - yScale(d.frequency);
return (<Bar
x={xScale(d.letter)}
y={yMax - barHeight}
width={xScale.bandwidth()}
height={barHeight}
fill="rgba(23, 233, 217, .5)"
/>);
})}
</svg>);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment