来源:https://blog.csdn.net/david_jiahuan/article/details/80096922

案例一

项目中现有样式:

客户需求:将图例分为两列,并且上下两列的图例要对齐:

==================================================

具体思路:将原有的一个 legend,分成7个小 legend 显示(形容的可能不太形象,下面看代码吧):

(1)原先的代码:

  1. legend: {
  2. orient: 'horizontal',
  3. top:'8%',
  4. right:'0%',
  5. data: ['0-5分钟','5-15分钟','15-30分钟','30-60分钟','60-120分钟','120-240分钟','大于240分钟'],
  6. textStyle:{
  7. fontSize: difSize_title,
  8. color:'#fff'
  9. }
  10. }

(2)修改后的代码:

  1. legend:[
  2. {
  3. orient: 'horizontal',
  4. <span style="color:#ff0000;">x : '5%',
  5. y : '10%',</span>
  6. align: 'left',
  7. data: ['0-5分钟'],
  8. textStyle:{
  9. fontSize: difSize_legend,
  10. color:'#fff'
  11. }
  12. },{
  13. orient: 'horizontal',
  14. <span style="color:#ff0000;"> x : '30%',
  15. y : '10%',</span>
  16. align: 'left',
  17. data: ['5-15分钟'],
  18. textStyle:{
  19. fontSize: difSize_legend,
  20. color:'#fff'
  21. }
  22. },{
  23. orient: 'horizontal',
  24. <span style="color:#ff0000;">x : '55%',
  25. y : '10%',</span>
  26. align: 'left',
  27. data: ['15-30分钟'],
  28. textStyle:{
  29. fontSize: difSize_legend,
  30. color:'#fff'
  31. }
  32. },{
  33. orient: 'horizontal',
  34. <span style="color:#ff0000;"> x : '80%',
  35. y : '10%',</span>
  36. align: 'left',
  37. data: ['30-60分钟'],
  38. textStyle:{
  39. fontSize: difSize_legend,
  40. color:'#fff'
  41. }
  42. },{
  43. orient: 'horizontal',
  44. <span style="color:#ff0000;"> x : '5%',
  45. y : '15%',</span>
  46. align: 'left',
  47. data: ['60-120分钟'],
  48. textStyle:{
  49. fontSize: difSize_legend,
  50. color:'#fff'
  51. }
  52. },{
  53. orient: 'horizontal',
  54. <span style="color:#ff0000;">  x : '30%',
  55. y : '15%',</span>
  56. align: 'left',
  57. data: ['120-240分钟'],
  58. textStyle:{
  59. fontSize: difSize_legend,
  60. color:'#fff'
  61. }
  62. },{
  63. orient: 'horizontal',
  64. <span style="color:#ff0000;">  x : '55%',
  65. y : '15%',</span>
  66. align: 'left',
  67. data: ['大于240分钟'],
  68. textStyle:{
  69. fontSize: difSize_legend,
  70. color:'#fff'
  71. }
  72. }
  73. ],

==========关键点就是每个小legend的x和y的值!定好每个小legend所在的绝对位置!

案例二

1效果图

2)代码

//饼图二级
function RowOnClickPieShow2(rowPieA) {
//一级数据
var rowPie = {};
//二级数据
var rowPie2 = {};
if (rowPieA.区域) {
var pieLevel = 0;
if (Level==1) {
pieLevel = 2;
}else if(Level==2){
pieLevel = 1;
}
var url = "@Url.Action("LandscapePie")";
$.post(url, { regionName: rowPieA.区域, level: pieLevel, year: YearSelect }, function (result) {
// console.log(result)
for (var i = 0; i < result.length; i++) {
var obj = result[i];
if (obj.FactorLevel == 1) {
for (var j = 1; j < className.length; j++) {
if (obj.ClassName == className[j]) {
rowPie[obj.ClassName] = obj.Area.toFixed(2);
}
}
} else if (obj.FactorLevel == 2) {
for (var k = 1; k < className2.length; k++) {
if (obj.ClassName == className2[k]) {
rowPie2[obj.ClassName] = obj.Area.toFixed(2);
}
}
}
}
//console.log(rowPie);
//console.log(rowPie2);
var option1 = {
title: {
text: YearSelect + '年' + rowPieA.区域 + '景观要素类型面积统计饼图',
//subtext: '纯属虚构',
x: 'center',
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
legend: [
{
orient: 'horizontal',
x: '1%',
y: '10%',
align: 'left',
data: ['植被'],
},
{
orient: 'horizontal',
x: '20%',
y: '10%',
align: 'left',
data: ['林地'],
},
{
orient: 'horizontal',
x: '20%',
y: '19%',
align: 'left',
data: ['草地'],
},
{
orient: 'horizontal',
x: '20%',
y: '28%',
align: 'left',
data: ['农田'],
}, {
orient: 'horizontal',
x: '1%',
y: '37%',
align: 'left',
data: ['水体'],
},
{
orient: 'horizontal',
x: '20%',
y: '37%',
align: 'left',
data: ['水体'],
}, {
orient: 'horizontal',
x: '1%',
y: '46%',
align: 'left',
data: ['不透水'],
},
{
orient: 'horizontal',
x: '20%',
y: '46%',
align: 'left',
data: ['建筑'],
},
{
orient: 'horizontal',
x: '20%',
y: '55%',
align: 'left',
data: ['道路'],
},
{
orient: 'horizontal',
x: '20%',
y: '64%',
align: 'left',
data: ['其他不透水'],
}, {
orient: 'horizontal',
x: '1%',
y: '73%',
align: 'left',
data: ['裸地'],
},
{
orient: 'horizontal',
x: '20%',
y: '73%',
align: 'left',
data: ['裸土'],
},
{
orient: 'horizontal',
x: '20%',
y: '82%',
align: 'left',
data: ['在建用地'],
} ] ,
series: [
{
name: '一级',
type: 'pie',
center: ['70%', '50%'],
radius: [0, '30%'],
label: {
normal: {
show: false,
}
},
data: [
{ value: rowPie.植被, name: '植被', itemStyle: { normal: { color: 'rgb(38,115,0)' } } },
{ value: rowPie.水体, name: '水体', itemStyle: { normal: { color: 'rgb(0,0,255)' } } },
{ value: rowPie.不透水, name: '不透水', itemStyle: { normal: { color: 'rgb(189,0,0)' } } },
{ value: rowPie.裸地, name: '裸地', itemStyle: { normal: { color: 'rgb(255,255,0)' } } }
]
},
{
name: '二级',
type: 'pie',
center: ['70%', '50%'],
radius: ['40%', '60%'],
label: {
normal: {
show: false,
}
},
data: [
{ value: rowPie2.林地, name: '林地', itemStyle: { normal: { color: 'rgb(0,128,0)' } } },
{ value: rowPie2.草地, name: '草地', itemStyle: { normal: { color: 'rgb(0,255,0)' } } },
{ value: rowPie2.农田, name: '农田', itemStyle: { normal: { color: 'rgb(255,255,160)' } } },
{ value: rowPie2.水体, name: '水体', itemStyle: { normal: { color: 'rgb(0,0,255)' } } },
{ value: rowPie2.建筑, name: '建筑', itemStyle: { normal: { color: 'rgb(189,0,0)' } } },
{ value: rowPie2.道路, name: '道路', itemStyle: { normal: { color: 'rgb(128,128,128)' } } },
{ value: rowPie2.其他不透水, name: '其他不透水', itemStyle: { normal: { color: 'rgb(192,220,192)' } } },
{ value: rowPie2.裸土, name: '裸土', itemStyle: { normal: { color: 'rgb(255,255,0)' } } },
{ value: rowPie2.在建用地, name: '在建用地', itemStyle: { normal: { color: 'rgb(255,233,233)' } } }
]
}
]
};
//使用指定的配置项和数据显示图表
pie_chart1.setOption(option1,true);
});
} }

  

// 上面的变量显示的中文,实际用的是英文。

//以上代码还有改进空间,比如:legend,data 可以通过 for循环得到,特别是某些需要动态显示一部分内容的情况。

Echarts图表legend的排版问题(转载)的更多相关文章

  1. 在vue中使用echarts图表

    在vue中使用echarts图表   转载请注明出处:https://www.cnblogs.com/wenjunwei/p/9815290.html 安装vue依赖 使用npm npm instal ...

  2. echarts图表第一个案例

    1.action中获取到数据 @Override public String execute() throws Exception { List<Student> find = echar ...

  3. echarts图表标签(axisLabel)折行

    在项目中遇到了一个echarts图表标签过长需折行的需求,so引出这篇总结,啦啦啦有帮助就多多支持啦,撒花撒花撒花~~~~ 在此不对echarts其他用法做解释,详细见echarts文档(点击前往) ...

  4. Echarts图表控件使用总结2(Line,Bar)—问题篇

    Echarts图表控件使用总结1(Line,Bar):http://www.cnblogs.com/hanyinglong/p/Echarts.html 1.前言 a.前两天简单写了一篇在MVC中如何 ...

  5. ***ECharts图表入门和最佳实践

    ECharts数据图表系统? 5分钟上手! [ECharts简介] ECharts开源来自百度商业前端数据可视化团队,基于html5 Canvas,是一个纯Javascript图表库,提供直观,生动, ...

  6. ASP.NET MVC + ECharts图表案例

    废话不多说直接讲讲今天要做的事. 利用微软爸爸的MVC框架结合百度的良心产品ECharts图表进行动态图表的生成,本文以柱状图为例. ECharts下载以及相关文档:http://echarts.ba ...

  7. vue-cli ——解决多次复用含有Echarts图表组件的问题

    在vue项目里,组件复用是一件很开心的事,可以节省很多时间去排版,达到事半功倍效果,但是昨晚在vue-cli项目里组件复用时发现基于Echarts图表的组件不能够复用,昨晚捯饬了很久,终于还是解决了这 ...

  8. C#WinForm应用程序中嵌入ECharts图表

    C#WinForm应用程序中嵌入ECharts图表 程序运行效果: 下载ECharts: 官网下载ECharts :http://echarts.baidu.com/download.html 或者直 ...

  9. Echarts图表常用功能配置,Demo示例

    先看下效果图: 就如上图所示,都是些常用的基本配置. Legend分页,X轴设置,Y轴设置,底部缩放条设置, 数值显示样式设置,工具箱设置,自定义工具按钮, 绑定点击事件等等.这些配置代码中都做了简单 ...

随机推荐

  1. css基础回顾

    1.css选择器分类: id选择器,类选择器,通用选择器, 包含(后代)选择器——加入空格,用于选择指定标签元素下的后辈元素. 子选择器(大于符号)——用于指定标签元素的第一代子元素. 伪类选择器—— ...

  2. bootstrap概述

    前面的话 Bootstrap是简单.灵活的用于搭建WEB页面的HTML.CSS.Javascript的工具集.Bootstrap基于HTML5和CSS3,具有漂亮的设计.友好的学习曲线.卓越的兼容性, ...

  3. win10个人助理conrtana软件能否支持用户反馈、后续优化

    上网查找了一下,win10的个人助理不支持用户反馈.这些反馈都是用户通过别的途径来发表反馈的信息,这个缺陷让用户不是特别满意,因为反馈信息不再那么简答,变得越来越繁琐.有些人还会担心自己反馈的问题会不 ...

  4. 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础

    [源码下载] 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础 作者:webabcd 介绍背水一战 Wi ...

  5. Python selenium webdriver设置加载页面超时

    1.  pageLoadTimeout: pageLoadTimeout方法用来设置页面完全加载的超时时间,完全加载即页面全部渲染,异步同步脚本都执行完成.没有设置超时时间默认是等待页面全部加载完成才 ...

  6. Redis安装和实际应用

    上次介绍了Redis的来龙去脉以及相关一些情况,点击回顾<深入浅出Redis>,接下来我们再讲讲Redis的安装和实际应用. 一.Redis的安装 下载安装包,redis-3.2.9.ta ...

  7. Javascript高级编程学习笔记(59)—— 事件(3)事件对象

    事件对象 在触发DOM‘事件时,会产生一个事件对象 event 该对象包含着所有与事件有关的信息 所有浏览器都支持 event 对象但是支持的方式有所不同 DOM事件对象 兼容DOM的浏览器会将eve ...

  8. select count(*) 底层究竟做了什么?

    阅读本文大概需要 6.6 分钟. SELECT COUNT( * ) FROM t是个再常见不过的 SQL 需求了.在 MySQL 的使用规范中,我们一般使用事务引擎 InnoDB 作为(一般业务)表 ...

  9. 第83节:Java中的学生管理系统分页功能

    第83节:Java中的学生管理系统分页功能 分页功能一般可以做成两种,一种是物理分页,另一种是逻辑分页.这两种功能是有各自的特点的,物理分页是查询的时候,对数据库进行访问,只是查一页数据就进行返回,其 ...

  10. java后端服务器读取excel将数据导入数据库

    使用的是easypoi,官网文档:http://easypoi.mydoc.io/ /** * 导入Excel文件 */ @PostMapping("/importTeacher" ...