鸿蒙图表——三方库


import { chartInterface, McBarChart, McLineChart, Options } from '@mcui/mccharts'

@Entry
@Component
struct Index {
  @State McBarChart: Options|null =  null
  @State dataZoomOption: Options|null = null



  aboutToAppear(): void {
    this.getBarChart()
    this.getLineChart()
  }

  //绘制柱状图
  getBarChart(){
    this.McBarChart = new Options({
      xAxis:{
        axisLine: { // 轴线样式
          show: true, // 是否显示
          lineStyle: {
            color: '#ccc',
            width: 1
          }
        },
        axisTick: { // 刻度线配置
          show: false, // 是否显示
          length: 4, // 刻度的长度
          lineStyle: {
            color: '#ccc', // 刻度线颜色
            width: 2 // 刻度线宽度
          }
        },
        axisLabel: {  // x轴文本标签样式
          fontWeight: '600',
          fontFamily: 'sans-serif',
          fontSize: 30,
        },
        // formatter: (name: string) => { // 自定义文本标签
        //   return '周六'
        // },
        data: ['周一','周二','周三','周四','周五','周六','周日'] // 数据
      },
      yAxis:{
        name:'温度'
      },
      series:[
        {
          name:'最高气温',
          data:[11, 110, 15, 130, 12, 130, 10]
        }
      ]
    })
  }

  // 绘制折线图
  getLineChart(){
    this.dataZoomOption =new Options({
      xAxis:{
        data: ['周一','周二','周三','周四','周五','周六','周日'] // 数据
      },
      series:[
        {
          name:'最高气温',
          color: '#ff2659f5', // 自定义颜色
          lineStyle: { // 折线样式配置
            width: 2,
            type: 'solid'
          },
          label: { // 文本标签样式
            fontWeight: '600',
            fontFamily: 'sans-serif',
            fontSize: 30,
            // 自定义文本
            // formatter: (params: chartInterface.InterfaceObj): string => {
            //   return params.name
            // },
          },
          itemStyle: { // 转折点的样式
            symbol: 'solidCircle',
            symbolSize: 2,
            symbolColor: '#fff',
            borderWidth: 1,
            borderType: 'solid',
            borderColor: '#ff2659f5'
          },
          // 平滑曲线
          smooth: true,
          // 区域颜色,线性渐变
          // areaStyle: {
          //   color: {
          //     direction: [0, 1, 0, 0], // 渲染角度
          //     colors: [ // 颜色的分布
          //       {
          //         offset: 0,
          //         color: '#f72659f5'
          //       },
          //       {
          //         offset: 0.5,
          //         color: '#f72659f5'
          //       },
          //       {
          //         offset: 1,
          //         color: '#002659f5'
          //       }
          //     ]
          //   }
          // },
          data:[11, 110, 15, 130, 12, 130, 10] // 数据
        }
      ]
    })
  }
  build() {
    Stack() {
      McBarChart({
        options: this.McBarChart
      })
        .zIndex(88)
        .margin({top:-9})
      McLineChart({
        options: this.dataZoomOption
      })
    }
    .height('50%')
    .align(Alignment.Top)
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值