// SCL-90 (function () { // 获取url var js = 'scl90' var scripts = document.querySelectorAll('script[src*="/lb/chart/' + js + '.js"]') var script = scripts[scripts.length - 1] var src = script.src // 获取参数 var w = src.match(/[?&]w=([^&]+)/) var h = src.match(/[?&]h=([^&]+)/) var v = src.match(/[?&]v=([^&]+)/) // 处理参数 if (w === null || w.length < 1) { w = '100%' } else { w = w[1] + 'px' } if (h === null || h.length < 1) { h = 400 } else { h = h[1] } if (v === null || v.length < 1) { v = '' } else { v = v[1] } // 处理得分,只取前10个 var json = v.replace(/\|/g, ',').split(',').slice(0, 10) // 折线图配置 var option = { grid: { left: 'left', containLabel: true, right: 30, bottom: 0 }, title: { text: '症状自评量表(SCL-90)剖析图' }, tooltip: { trigger: 'axis' }, toolbox: { feature: { dataView: {}, magicType: { type: ['bar'] }, restore: {}, saveAsImage: {} } }, xAxis: { axisLabel: { interval: 0, rotate: 30 }, data: ['躯体化', '强迫症状', '人际敏感', '抑郁', '焦虑', '敌对', '恐怖', '偏执', '精神病性', '其他'] }, yAxis: { max: 5 }, series: { name: '均分', type: 'line', smooth: false, markPoint: { data: [{ name: '最大值', type: 'max', itemStyle: { color: '#b6a2de', opacity: 0.8 } }] }, markLine: { silent: true, data: [{ yAxis: 2.5, lineStyle: { color: '#b6a2de', opacity: 0.5 } }] }, data: json } } // 创建容器 var rnd = Math.random().toString().substring(2, 8) var div = '
' script.insertAdjacentHTML('afterend', div) script.parentNode.removeChild(script) // 处理主题 var body = document.getElementsByTagName('body')[0] if (body.getAttribute('data-echarts-theme-macarons')) { drawChart() } else { // 原生获取太难处理,还是用jquery $.ajax('/Scripts/echarts/theme/macarons.js', { dataType: 'script', cache: true, complete: function () { body.setAttribute('data-echarts-theme-macarons', true) drawChart() } }) } // 绘制图表 function drawChart() { var dom = document.getElementById('chart-' + rnd) dom.setAttribute('data-option', JSON.stringify(option)) dom.setAttribute('data-theme', 'macarons') echarts.init(dom, 'macarons').setOption(option) } })()