Skip to content

Instantly share code, notes, and snippets.

@spkellydev
Created January 12, 2019 15:23
Show Gist options
  • Save spkellydev/f52eb82987104e9307e654e252182fe7 to your computer and use it in GitHub Desktop.
Save spkellydev/f52eb82987104e9307e654e252182fe7 to your computer and use it in GitHub Desktop.
legendMarkup = chart => {
console.log(chart);
const legendSet = chart.data.datasets[0];
const legend = legendSet.data.map((set, i) => {
let datapoint = chart.data.labels[i];
if (datapoint) {
return (
<li
id={`${datapoint.replace(/\s/g, "")}`}
key={datapoint}
onClick={e => this.handleLegendOnClick(e)}
className="legend-group--item list-group-item"
data-idx={i}
data-quantity={legendSet.data[i]}
style={{ borderColor: legendSet.backgroundColor[i] }}
>
<mark
style={{
backgroundColor: legendSet.backgroundColor[i] || "#e5e5e5"
}}
>
{legendSet.data[i]}
</mark>
{`${datapoint.replace(/\(\d{1, 6}\)$/g, "")}`}
</li>
);
}
return "";
});
return legend;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment