a543462378 2022-03-30 10:34 采纳率: 84.7%
浏览 54
已结题

react项目使用bizcharts画图

react项目使用Chart画柱状图,图中的数据来自后端接口,这样要怎么画出效果中的样式?
要求效果图

img


后端接口数据

img


我现在画出来的效果

img


效果代码

queryGreat({
            thisMonth: params.month[0].format("YYYY-MM"),
            otherMonth: params.month[1].format("YYYY-MM"),
        }).then(res => {
            if (res.code === '0' && Array.isArray(res.data) && res.data.length === 3) {
                let allData = res.data
                setChartData(allData)
            }
        })
<Chart height={400} data={data.map(item => {
      item.pino = parseFloat(item.pino)
      return item;
    })} forceFit padding={[48, 48, 64, 64]}>
      <Axis name="type" />
      <Axis name="thisAmount" label={{
        formatter: (text) => {
          return `${text} kg`
        }
      }} />
      <Axis name="otherAmount" label={{
        formatter: (text) => {
          return `${text} kg`
        }
      }} />
      <Axis name="proportion" label={{
        formatter: (text) => {
          return `${text} %`
        }
      }} />
      <Tooltip />
      <Legend color='label' />
      <Interval type='interval' position="type*otherAmount" 
        tooltip={['label*type*otherAmount', (label, type, otherAmount,) => {
          return {
            //自定义 tooltip 上显示的 title 显示内容等。
            name: label,
            title: type,
            value: otherAmount + ' kg'
          };
        }]}
        adjust={[
          {
            type: "dodge",
            marginRatio: 1 / 32
          }
        ]}
      />
      <Line position='type*proportion' 
        tooltip={['label*type*proportion', (label, type, proportion) => {
          return {
            //自定义 tooltip 上显示的 title 显示内容等。
            name: label,
            title: type,
            value: proportion + ' %'
          };
        }]}
      />
    </Chart>
  )
}

要怎么处理数据才能做出效果图中的样式?

  • 写回答

2条回答 默认 最新

  • iloveozz 2022-03-30 14:06
    关注

    你用的是这个么,可以看看人家的写法,react本身是没有chart组件的,一般都是引入recharts库

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月10日
  • 已采纳回答 4月2日
  • 修改了问题 3月30日
  • 创建了问题 3月30日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度