re-chart
Version:
A react chart library powered by ECharts
29 lines (24 loc) • 780 B
JavaScript
import React, { Component, PropTypes } from 'react'
import BaseChart from '../BaseChart'
import 'echarts/lib/chart/pie'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/legend'
const Pie = ({ name, data = [], style, callback }) => {
const option = {
tooltip: { trigger: 'item', formatter: '{a} <br/>{b}: {c} ({d}%)' },
legend: { data: data.map(item => item.name) },
series: [{ name, type: 'pie', data }],
}
const props = { option, style, callback }
return <BaseChart { ...props } />
}
Pie.propTypes = {
title: PropTypes.string,
data: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string.isRequired,
value: PropTypes.number.isRequired,
})),
style: PropTypes.object,
callback: PropTypes.func,
}
export default Pie