Skip to content

Instantly share code, notes, and snippets.

@mpaccione
Created April 11, 2022 23:14
Show Gist options
  • Save mpaccione/18760aaf0a9008c55dce824d6f7acc7f to your computer and use it in GitHub Desktop.
Save mpaccione/18760aaf0a9008c55dce824d6f7acc7f to your computer and use it in GitHub Desktop.
Bar Example
import React from "react";
import Plot from "react-plotly.js";
const BarChart = ({ arr = false, obj, rect, title }) => {
if (!rect) {
return null;
}
const { height, width } = rect;
return (
<Plot
data={[
{
x: arr ? arr.map((val, idx) => idx) : Object.keys(obj),
y: arr ? arr : Object.values(obj),
type: "bar",
text: arr
? arr.map((val, idx) => idx).reverse()
: Object.keys(obj).map(String),
marker: { color: "rgb(29, 161, 60)" },
},
]}
layout={{ width, height, title }}
/>
);
};
export { BarChart };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment