Created
April 11, 2022 23:14
-
-
Save mpaccione/18760aaf0a9008c55dce824d6f7acc7f to your computer and use it in GitHub Desktop.
Bar Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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