Blogger Information
Blog 77
fans 0
comment 2
visits 55635
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
echarts移动端的适配思路
南瓜又个梦
Original
2840 people have browsed it

echarts移动端的适配思路

常规技巧

1,mate 标签viewport的设置,可以抄淘宝的
打开淘宝,切换成手机,刷新,然后copyhtml,找到mate标签复制

2,JS获取屏幕高度在设置在div上

  1. ducoment.ducomenElement.clientWidth

3,设定宽高比

  1. const width=document.documentElement.clientWidth
  2. main.style.width=`${width}px`
  3. main.style.height=`${width*1.2}px`

echarts提供的功能

baseOption+media
baseOption:是共用属性
media是查询属性
query:查询条件
option:放样式
echarts手机端适配

  1. myChart.setOption({
  2. baseOption: {
  3. xAxis: {
  4. type: 'category',
  5. data: date
  6. },
  7. yAxis: {
  8. type: 'value'
  9. },
  10. series: [
  11. {
  12. lineStyle: {
  13. color: '#c9c9c9',
  14. },
  15. itemStyle: {
  16. borderWidth: 5
  17. },
  18. data: values,
  19. type: 'line'
  20. }
  21. ]
  22. },
  23. media: [{
  24. query:{
  25. maxWidth:500
  26. },
  27. option:{
  28. series: [
  29. {
  30. lineStyle: {
  31. color: '#c0c9c9',
  32. },
  33. itemStyle: {
  34. borderWidth: 30
  35. },
  36. data: values,
  37. type: 'line'
  38. }
  39. ]
  40. }
  41. }]
  42. })

echarts 改外观

配合安装的@type/echarts

  1. yarn add --dev @type/echarts

点击事件的处理

  1. myChart.on('click',(e)=>{
  2. console.log(e)//e包含所有的事件信息
  3. window.open('www.baidu.com')
  4. })

点样式

线样式

添加数据

  1. let isLoading=false;//这是一个阻挡变量
  2. buttonId.addEventListener('click',()=>{
  3. if(isLoading===true){return}
  4. myChart.showLoading()
  5. isLoading=true
  6. setTimeout(()=>{
  7. date=[...date,createKey()]
  8. values=[...values,createValue()]
  9. myChart.setOption({
  10. xAxis:{ data: date},
  11. series:[{data: values}]
  12. })
  13. myChart.hideLoading()
  14. isLoading=false
  15. },3000)
  16. })
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post