react-chartjs-2#Pie TypeScript Examples
The following examples show how to use
react-chartjs-2#Pie.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From metaplex with Apache License 2.0 | 6 votes |
MemoizedPie = React.memo(function PieImpl(props: {
byType: Record<AuctionType, number>;
}) {
const pieData = {
labels: ['Open', 'Limited', 'Tiered', 'One of a Kind'],
datasets: [
{
label: '#',
data: [
props.byType[AuctionType.Open],
props.byType[AuctionType.Limited],
props.byType[AuctionType.Tiered],
props.byType[AuctionType.OneOfKind],
],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
],
borderWidth: 1,
},
],
};
return <Pie data={pieData} />;
})
Example #2
Source File: DataDocChart.tsx From querybook with Apache License 2.0 | 5 votes |
DataDocChart = React.memo<IDataDocChartProps>(
({ meta, data = [], chartJSOptions = {}, chartJSRef }) => {
const theme = useSelector(
(state: IStoreState) => state.user.computedSettings.theme
);
React.useEffect(() => {
Chart.defaults.color = `rgb(
${fontColor[theme][0]},
${fontColor[theme][1]},
${fontColor[theme][2]}
)`;
Chart.defaults.font = {
family: 'Avenir Next',
size: 14,
style: 'normal',
weight: undefined,
lineHeight: 1.2,
};
Chart.defaults.plugins.filler.propagate = true;
}, [theme]);
const [xAxesScaleType, yAxesScaleType] = useChartScale(meta, data);
const chartData = processChartJSData(
data,
meta,
theme,
xAxesScaleType,
yAxesScaleType
);
const combinedChartJSOptions = useMemo(
() => ({
...mapMetaToChartOptions(
meta,
theme,
xAxesScaleType,
yAxesScaleType
),
...chartJSOptions,
}),
[meta, theme, xAxesScaleType, yAxesScaleType, chartJSOptions]
);
const chartProps = {
data: chartData,
plugins: [ChartDataLabels],
options: combinedChartJSOptions,
ref: chartJSRef,
};
let chartDOM = null;
if (meta.chart.type === 'line' || meta.chart.type === 'area') {
chartDOM = <Line {...chartProps} />;
} else if (
meta.chart.type === 'bar' ||
meta.chart.type === 'histogram'
) {
chartDOM = <Bar {...chartProps} />;
} else if (meta.chart.type === 'pie') {
chartDOM = <Pie {...chartProps} />;
} else if (meta.chart.type === 'doughnut') {
chartDOM = <Doughnut {...chartProps} />;
} else if (meta.chart.type === 'scatter') {
chartDOM = <Scatter {...chartProps} />;
} else if (meta.chart.type === 'bubble') {
chartDOM = <Bubble {...chartProps} />;
}
return (
<DataDocChartWrapper size={meta.visual.size}>
{chartDOM}
</DataDocChartWrapper>
);
}
)