mirror of
https://github.com/status-im/nimbus-gui.git
synced 2025-02-28 02:50:45 +00:00
feat(half pie chart): create new pie chart
This commit is contained in:
parent
2b27e5b72b
commit
7d7db6d42c
66
src/components/Charts/HalfDoughnutWithGradient.tsx
Normal file
66
src/components/Charts/HalfDoughnutWithGradient.tsx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { Doughnut } from 'react-chartjs-2'
|
||||||
|
import {
|
||||||
|
Chart as ChartJS,
|
||||||
|
ArcElement,
|
||||||
|
Tooltip,
|
||||||
|
Legend,
|
||||||
|
ChartOptions,
|
||||||
|
} from 'chart.js'
|
||||||
|
import 'chartjs-plugin-gradient'
|
||||||
|
import { Stack } from 'tamagui'
|
||||||
|
|
||||||
|
ChartJS.register(ArcElement, Tooltip, Legend)
|
||||||
|
|
||||||
|
const options: ChartOptions<'doughnut'> = {
|
||||||
|
rotation: -90,
|
||||||
|
circumference: 180,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const DoughnutChartHalf = () => {
|
||||||
|
const data = {
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
data: [90, 10],
|
||||||
|
backgroundColor: function (context: any) {
|
||||||
|
const chart = context.chart
|
||||||
|
const { ctx, chartArea } = chart
|
||||||
|
|
||||||
|
if (!chartArea) {
|
||||||
|
// This case happens on initial chart load
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
// Create the gradient for the first dataset (90%)
|
||||||
|
const gradient = ctx.createLinearGradient(
|
||||||
|
chartArea.left,
|
||||||
|
0,
|
||||||
|
chartArea.right,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
gradient.addColorStop(0.0024, '#FF7D46')
|
||||||
|
gradient.addColorStop(0.6216, '#FFA800')
|
||||||
|
gradient.addColorStop(0.9406, '#1992D7')
|
||||||
|
|
||||||
|
return [gradient, '#F5F6F8']
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
labels: ['Gradient', 'Solid'],
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack width={'100px'} height={'100px'} padding={0} margin={0}>
|
||||||
|
<Doughnut data={data} options={options} />
|
||||||
|
</Stack>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DoughnutChartHalf
|
@ -2,6 +2,8 @@ import { Separator, Stack, XStack, YStack } from 'tamagui'
|
|||||||
import DashboardCardWrapper from '../DashboardCardWrapper'
|
import DashboardCardWrapper from '../DashboardCardWrapper'
|
||||||
import { Text } from '@status-im/components'
|
import { Text } from '@status-im/components'
|
||||||
import HalfTopGauge from '../../../components/Charts/HalfTopGauge'
|
import HalfTopGauge from '../../../components/Charts/HalfTopGauge'
|
||||||
|
import HalfDoughnutWithGradient from '../../../components/Charts/HalfDoughnutWithGradient'
|
||||||
|
import DoughnutChartHalf from '../../../components/Charts/HalfDoughnutWithGradient'
|
||||||
|
|
||||||
const ConnectedPeers = () => {
|
const ConnectedPeers = () => {
|
||||||
const data = [
|
const data = [
|
||||||
@ -33,7 +35,7 @@ const ConnectedPeers = () => {
|
|||||||
16
|
16
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<HalfTopGauge data={data} />
|
<DoughnutChartHalf></DoughnutChartHalf>
|
||||||
</XStack>
|
</XStack>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Separator borderColor={'#e3e3e3'} />
|
<Separator borderColor={'#e3e3e3'} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user