自定义echarts图表滚动条样式:
代码:
图表的html格式为:
<div className="medicFeeStyl">
<div id="medicFeePic" style={{ width: '100%', height: '100%' }}></div>
<div id="noDataImg6" style={{ width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<img src={noDataPic} alt="" style={{ width: 140, height: 130, display: 'inline-block' }}></img>
</div>
</div>
valData的数据格式为:
const costPandectPicAll = { xAxis: [], series: [{ data: [] }, { data: [] }, { data: [] }, { data: [] }, { data: [] }, { data: [] }, { data: [] }, { data: [] }] };
this.getCostPandectBar(costPandectPicAll)
getCostPandectBar = (valData) => {
const { profitByDeptList } = this.state
if (profitByDeptList === null || profitByDeptList.length === 0) { // 获取的数据源
$('#noDataImg6').show() //无数据时显示一张自定义图片展示
$('#medicFeePic').hide()
return {}
} else {
$('#noDataImg6').hide()
$('#medicFeePic').show()
const xAxis = valData.xAxis;
const series = valData.series
const { adminValue } = this.state
var option = {
tooltip: {
trigger: 'axis',
textStyle: {
color: 'rgba(0,0,0,0.65)',
fontSize: 14,
fontWeight: 'normal'
},
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'line' // 默认为直线,可选为:'line' | 'shadow'
},
extraCssText: 'min-width:300px',
position: function (pos, params, dom, rect, size) {
if((pos[0]+size.contentSize[0])>size.viewSize[0]){
return 'left'
}
},
formatter: function (param) {
if (param.length > 0) {
var newTip = ""
for (var i = 1; i < param.length; i++) {
if (param[i].data.ratio == undefined) {
newTip += `<div style="display:flex;justify-content: space-between;"><span style="min-width:100px">${param[i].marker}${param[i].seriesName}</span> <span style="margin-right:24px;text-align:right;min-width:100px;font-weight:600;color:rgba(0,0,0,0.85)"> ${param[i].data.value} 元</span><span style="min-width:60px;text-align:right;font-weight:600;color:rgba(0,0,0,0.85)"></span></div>`
} else {
newTip += `<div style="display:flex;justify-content: space-between;"><span style="min-width:100px">${param[i].marker}${param[i].seriesName}</span> <span style="margin-right:24px;text-align:right;min-width:100px;font-weight:600;color:rgba(0,0,0,0.85)"> ${param[i].data.value} 元</span><span style="min-width:60px;text-align:right;font-weight:600;color:rgba(0,0,0,0.85)">${param[i].data.ratio}%</span> </div>`
}
}
if (adminValue != 2) {
return `${param[0].name}<br/><div style="display:flex;justify-content: space-between;"><span style="min-width:100px">${param[0].marker}${param[0].seriesName}</span> <span style="margin-right:24px;text-align:right;min-width:100px;font-weight:600;color:rgba(0,0,0,0.85)"> ${param[0].data.value} 元</span><span style="min-width:60px;text-align:right;font-weight:600;color:rgba(0,0,0,0.85)"></span></div><div style="display:flex;justify-content: space-between;"><span style="min-width:100px;text-indent:13px">总费用</span> <span style="margin-right:24px;text-align:right;min-width:100px;font-weight:600;color:rgba(0,0,0,0.85)"> ${param[0].data.total}元</span><span style="min-width:60px;text-align:right;font-weight:600;color:rgba(0,0,0,0.85)"></span></div>${newTip}`
} else {
return `[${param[0].name}] ${param[0].data.drgName}<br/><div style="display:flex;justify-content: space-between;"><span style="min-width:100px">${param[0].marker}${param[0].seriesName}</span> <span style="margin-right:24px;text-align:right;min-width:100px;font-weight:600;color:rgba(0,0,0,0.85)"> ${param[0].data.value} 元</span><span style="min-width:60px;text-align:right;font-weight:600;color:rgba(0,0,0,0.85)"></span></div><div style="display:flex;justify-content: space-between;"><span style="min-width:100px;text-indent:13px">总费用</span> <span style="margin-right:24px;text-align:right;min-width:100px;font-weight:600;color:rgba(0,0,0,0.85)"> ${param[0].data.total}元</span><span style="min-width:60px;text-align:right;font-weight:600;color:rgba(0,0,0,0.85)"></span></div>${newTip}`
}
}
}
},
dataZoom: profitByDeptList.length > 20 ? [//给x轴设置滚动条
{
start: 0,//默认为0
end: 100,//默认为100
type: 'slider',
show: true,
zoomLock: false,
brushSelect: false, //滚动条只允许滑动,不允许框选范围
maxValueSpan: 19,
minValueSpan: 19,
xAxisIndex: [0],
moveHandleSize: 0,
handleSize: 0,//滑动条的 左右2个滑动条的大小
height: 10,//组件高度
left: '10%', //左边的距离
right: '10%',//右边的距离
bottom: 22,//下边的距离
borderColor: "#ffffff",
fillerColor: '#d8d8d8', //选中滑条颜色
borderRadius: 5,
dataBackground: '#ffffff',
backgroundColor: '#ffffff',//两边未选中的滑动条区域的颜色
showDataShadow: false,//是否显示数据阴影 默认auto
showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
realtime: true, //是否实时更新
filterMode: 'filter',
},
//下面这个属性是里面拖到
{
type: 'inside',
show: true,
zoomLock: true,
xAxisIndex: [0],
start: 0,//默认为1
end: 100,//默认为100
},
] : [],
color: ['#B2E3F3', '#009FD4', '#39D1AF', '#FFD45B', '#7FCFE9', '#7A7DFF', '#556FC6'],
grid: {
x: 16, //左
y: 30, //上
x2: 24, //右
y2: 32, //下
containLabel: true,
},
legend: {
bottom: 0,
left: 18,
icon: 'square',
textStyle: {//文字颜色
fontSize: 12,
color: 'rgba(0,0,0,0.65)'
},
itemWidth: 12,
itemHeight: 12,
itemGap: 16,
selectedMode: false,
data: ['医保赔付金额', '药材费', '手术费', '检查费', '耗材费', '诊疗服务', '其它']
},
xAxis: {
type: 'category',
data: xAxis,
nameTextStyle: {
color: 'rgba(0,0,0,0.45)',
fontSize: 14
},
axisLabel: {
interval: 'auto',
show: true,
textStyle: {
color: 'rgba(0,0,0,0.45)', //更改坐标轴文字颜色
fontSize: 14 //更改坐标轴文字大小
},
color: "rgba(0,0,0,0.45)",
formatter: function (value) {
let fuhaoValue;
if (adminValue != 2) {
fuhaoValue = value
} else {
fuhaoValue = '︹' + value + '︺'
}
value = fuhaoValue.toString();
var maxlength = 6;
var newValue;
if (value.length > maxlength) {
newValue = value.substring(0, maxlength);
return newValue.split("").join("\n")
} else {
return value.split("").join("\n");
}
},
},
axisLine: {
lineStyle: {
color: '#d9d9d9' //更改坐标轴颜色
},
onZero: false //为true时让轴在0点位置
}
},
yAxis: {
type: 'value',
name: '费用(元)',
nameTextStyle: {
color: 'rgba(0,0,0,0.45)',
fontSize: 14,
// padding: [0, 0, 0, -75]
},
splitLine: {
show: true,
lineStyle: {
color: ['#e8e8e8'],
width: 1,
type: 'dashed'
}
},
axisLabel: {
textStyle: {
align: 'right',
fontSize: 14 // 文字右对齐
},
color: "rgba(0,0,0,0.45)",
}
},
series: [
{
name: '医保赔付金额',
type: 'bar',
barWidth: 6,
emphasis: {
focus: 'series'
},
data: series[7].data
},
{
name: '药材费',
type: 'bar',
barWidth: 6,
stack: '费用',
emphasis: {
focus: 'series'
},
data: series[1].data
},
{
name: '手术费',
type: 'bar',
barWidth: 6,
stack: '费用',
emphasis: {
focus: 'series'
},
data: series[3].data
},
{
name: '检查费',
type: 'bar',
barWidth: 6,
stack: '费用',
emphasis: {
focus: 'series'
},
data: series[2].data
},
{
name: '耗材费',
type: 'bar',
barWidth: 6,
stack: '费用',
emphasis: {
focus: 'series'
},
data: series[4].data
},
{
name: '诊疗服务',
type: 'bar',
barWidth: 6,
stack: '费用',
emphasis: {
focus: 'series'
},
data: series[5].data
},
{
name: '其它',
type: 'bar',
barWidth: 6,
stack: '费用',
emphasis: {
focus: 'series'
},
data: series[6].data
}
]
};
var medicFeePic = echarts.init(document.getElementById('medicFeePic'));
medicFeePic.clear()
medicFeePic.setOption(option);
}
window.addEventListener("resize", function () {
medicFeePic.resize();
}); //监听浏览器窗口变化视图随之更新
}