Skip to content

Instantly share code, notes, and snippets.

@jokamjohn
Created May 3, 2020 10:48
Show Gist options
  • Save jokamjohn/50fc4191856a7d6e5dbaceeaa10df0c4 to your computer and use it in GitHub Desktop.
Save jokamjohn/50fc4191856a7d6e5dbaceeaa10df0c4 to your computer and use it in GitHub Desktop.
import React from "react";
import styled from "styled-components";
import { VictoryChart, VictoryBar, VictoryTooltip } from "victory";
const Container = styled("div")`
font-family: sans-serif;
text-align: center;
`;
const data = [
{ name: "John", score: 20 },
{ name: "Joe", score: 10 },
{ name: "Jos", score: 30 },
{ name: "Joy", score: 15 },
{ name: "Joan", score: 40 },
{ name: "Johnny", score: 50 }
];
export default function App() {
return (
<Container>
<h1>VictoryTooltip</h1>
<VictoryChart>
<VictoryBar
data={data}
labels={({ datum }) => `Name: ${datum.name} score: ${datum.score}`}
labelComponent={
<VictoryTooltip
flyoutWidth={95}
flyoutHeight={35}
cornerRadius={5}
pointerLength={40}
flyoutStyle={{
stroke: "#868C97",
strokeWidth: 2,
fill: "#FFFFFF"
}}
style={{
fill: "#868C97",
fontSize: 10,
fontWeight: 500,
textAnchor: "middle"
}}
/>
}
x="score"
y="name"
/>
</VictoryChart>
</Container>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment