ZBLOG

let colors = ['#1ac47c', '#ffb661', '#ff625e']; option = { title: { text: 'CPU使用率', top: '4%', x: 'center', textStyle: { color: '#ffffff', fontSize: 24, fontWeight: 'normal'} }, series: [ { type: 'gauge', mi...

这段代码已经使用TypeScript进行了改写。请注意,在使用之前确保你的项目环境中有支持TypeScript的构建工具和相关依赖。如果你需要将这段代码用于前端框架(如React、Vue等),还需要与相关框架进行集成,以正确渲染和显示仪表盘。

let colors: string[] = ['#1ac47c', '#ffb661', '#ff625e'];

let option: Option = {
  title: {
    text: 'CPU使用率',
    top: '4%',
    x: 'center',
    textStyle: { color: '#ffffff', fontSize: 24, fontWeight: 'normal' }
  },

  series: [
    {
      type: 'gauge',
      min: 0,
      max: 100,
      axisLine: {
        lineStyle: {
          width: 36,
          color: [
            [0.7, colors[0]],
            [0.9, colors[1]],
            [1, colors[2]]
          ]
        }
      },
      splitLine:{
        length:'12%',
      },
      axisTick:{ show:false },
      axisLabel:{ fontSize :16 ,fontWeight :'bold',distance :10},
      pointer:{ width :12 ,length :'60%'},
      markPoint:{
        animation:false,
        silent:true,
        data:[
          {x:'50%',y:'50%',symbol:'circle',symbolSize:50},
          {x:'50%',y:'50%',symbol:'circle',symbolSize:30,itemStyle:{color:'#fff'}}
        ],
      },
      
       detail :{
           formatter :'{value}%',
           fontSize : 50 ,
           fontWeight :'bold'
       },
       
       data:[
           {
               value:95.66,
           }
       ]
    }
  ]
};

interface Option {
  title: {
    text: string;
    top: string;
    x: string;
    textStyle: { color: string; fontSize: number; fontWeight: string };
  };
  series: GaugeSeries[];
}

interface GaugeSeries {
  type: 'gauge';
  min?: number;
  max?: number;
  axisLine?: AxisLine;
  splitLine?: SplitLine;
  axisTick?: { show:boolean };
  axisLabel?: { fontSize:number ;fontWeight:string ;distance:number};
  pointer?: { width :number ,length :string};
   markPoint ?: MarkPoint
   detail ?:Detail
   data ?: DataItem[]
}

interface AxisLine{
lineStyle ?:{
width:number,
color:[number,string] | [[number,string],[number,string]] | [[number,string],[number,string],[number,string]]
}
}

interface SplitLine{
length? :string
}

interface MarkPoint{
animation ?:boolean ,
silent? :boolean,
data ?:MarkPointData[]
}

interface MarkPointData{
x:string,
y:string,
symbol ?:'circle',
symbolSize ?:number,
itemStyle ?:{color:string}
}


interface Detail{
formatter? :string,
fontSize:number,
fontWeight:string
}

 interface DataItem{
 value:number 
} 

请注意,这只是代码的类型声明和适配,实际在浏览器中使用时仍需加载ECharts库并进行相应的渲染配置。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=15401

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?