// MBTI职业性格测试 (function () { 'use strict' // 获取url var js = 'embti' 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] } // 处理得分 var json = v.replace(/\|/g, ',').split(',') var x1 = ['外向(E)', '实感(S)', '思考(T)', '判断(J)'] var x2 = ['内向(I)', '直觉(N)', '情感(F)', '认知(P)'] // 条形图 var option1 = { toolbox: { feature: { saveAsImage: {} } }, tooltip: { show: true, trigger: 'axis', axisPointer: { type: 'shadow' } }, grid: [ { top: 0, left: 0, containLabel: true, width: '50%', bottom: 0 }, { top: 0, right: 0, containLabel: true, width: '50%', bottom: 0 } ], xAxis: [ { type: 'value', inverse: true, axisLine: { show: false }, axisTick: { show: false } }, { gridIndex: 1, type: 'value', axisLine: { show: false }, axisTick: { show: false } } ], yAxis: [ { type: 'category', inverse: true, axisLine: { show: false }, axisTick: { show: false }, data: x1 }, { gridIndex: 1, type: 'category', inverse: true, position: 'right', axisLine: { show: false }, axisTick: { show: false }, data: x2 } ], series: [ { type: 'bar', label: { show: true, position: 'insideLeft' }, data: [json[0], json[2], json[4], json[6]] }, { xAxisIndex: 1, yAxisIndex: 1, type: 'bar', label: { show: true, position: 'insideRight' }, data: [json[1], json[3], json[5], json[7]] } ] } // 雷达图 var option2 = { toolbox: { feature: { saveAsImage: {} } }, tooltip: { show: true }, radar: { radius: '85%', indicator: [ { name: '外向(E)', max: 15 }, { name: '实感(S)', max: 15 }, { name: '思考(T)', max: 15 }, { name: '判断(J)', max: 15 }, { name: '内向(I)', max: 15 }, { name: '直觉(N)', max: 15 }, { name: '情感(F)', max: 15 }, { name: '认知(P)', max: 15 } ], startAngle: 112.5 }, series: { name: '因子', type: 'radar', areaStyle: {}, label: { show: true, color: '#B6A2DE' }, data: [{ value: [json[0], json[2], json[4], json[6], json[1], json[3], json[5], json[7]] }] } } // 旭日图 var option3 = { toolbox: { feature: { saveAsImage: {} } }, tooltip: { show: true, formatter: '{b}' }, series: { type: 'sunburst', label: { rotate: 'tangential' }, radius: [0, '99%'], nodeClick: false, itemStyle: { borderColor: '#666' }, data: [{ name: 'S', itemStyle: { color: '#CE3402' }, children: [{ name: 'Judging', itemStyle: { color: '#CC9900' }, children: [{ name: 'Guardians', label: { color: '#CC9900' }, itemStyle: { color: '#fff' }, children: [{ name: 'Thinking', itemStyle: { color: '#346633' }, children: [{ name: 'ESTJ', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'Supervisor', value: 1, itemStyle: { color: '#6A9ACB' } }] }, { name: 'ISTJ', value: 1, itemStyle: { color: '#CCCCCC' }, children: [{ name: 'Inspector', value: 1, itemStyle: { color: '#356798' } }] }] }, { name: 'Feeling', itemStyle: { color: '#349933' }, children: [{ name: 'ESFJ', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'Provider', value: 1, itemStyle: { color: '#689ACD' } }] }, { name: 'ISFJ', value: 1, itemStyle: { color: '#CCCCCC' }, children: [{ name: 'Protector', value: 1, itemStyle: { color: '#356798' } }] }] }] }] }, { name: 'Probing', itemStyle: { color: '#FFCC33' }, children: [{ name: 'Artisans', label: { color: '#FFCC33' }, itemStyle: { color: '#fff' }, children: [{ name: 'Thinking', itemStyle: { color: '#346633' }, children: [{ name: 'ESTP', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'Promotor', value: 1, itemStyle: { color: '#6598CD' } }] }, { name: 'ISTP', value: 1, itemStyle: { color: '#CCCCCC' }, children: [{ name: 'Crafter', value: 1, itemStyle: { color: '#356798' } }] }] }, { name: 'Feeling', itemStyle: { color: '#349931' }, children: [{ name: 'ESFP', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'Composer', value: 1, itemStyle: { color: '#6698C9' } }] }, { name: 'ISFP', value: 1, itemStyle: { color: '#CDCDCD' }, children: [{ name: 'Performer', value: 1, itemStyle: { color: '#356498' } }] }] }] }] }] }, { name: 'N', itemStyle: { color: '#FF3300' }, children: [{ name: 'Thinking', itemStyle: { color: '#349933' }, children: [{ name: 'Rationals', label: { color: '#339933' }, itemStyle: { color: '#fff' }, children: [{ name: 'Judging', itemStyle: { color: '#CB9A34' }, children: [{ name: 'ENTJ', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'General', value: 1, itemStyle: { color: '#6799CC' } }] }, { name: 'INTJ', value: 1, itemStyle: { color: '#CCCCCC' }, children: [{ name: 'Mastermind', value: 1, itemStyle: { color: '#336998' } }] }] }, { name: 'Probing', itemStyle: { color: '#FECD32' }, children: [{ name: 'ENTP', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'Inventor', value: 1, itemStyle: { color: '#669ACC' } }] }, { name: 'INTP', value: 1, itemStyle: { color: '#CCCCCC' }, children: [{ name: 'Architect', value: 1, itemStyle: { color: '#356498' } }] }] }] }] }, { name: 'Feeling', itemStyle: { color: '#346633' }, children: [{ name: 'Idealists', label: { color: '#346633' }, itemStyle: { color: '#fff' }, children: [{ name: 'Judging', itemStyle: { color: '#CD9934' }, children: [{ name: 'ENFJ', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'Mentor', value: 1, itemStyle: { color: '#6698CB' } }] }, { name: 'INFJ', value: 1, itemStyle: { color: '#CCCCCC' }, children: [{ name: 'Counselor', value: 1, itemStyle: { color: '#336598' } }] }] }, { name: 'Probing', value: 2, itemStyle: { color: '#FFCC33' }, children: [{ name: 'ENFP', value: 1, label: { color: '#666' }, itemStyle: { color: '#fff' }, children: [{ name: 'Champion', value: 1, itemStyle: { color: '#6797C8' } }] }, { name: 'INFP', value: 1, itemStyle: { color: '#CCCCCC' }, children: [{ name: 'Healer', value: 1, itemStyle: { color: '#346699' } }] }] }] }] }] }] } } // 创建容器 var rnd1 = Math.random().toString().substring(2, 8) var rnd2 = Math.random().toString().substring(2, 8) var rnd3 = Math.random().toString().substring(2, 8) var div = '' if (typeof (AMUI) !== 'undefined') { div = '
' } else { 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('//cdn.psy.com.cn/scripts/echarts/theme/macarons.js', { dataType: 'script', cache: true, complete: function () { body.setAttribute('data-echarts-theme-macarons', true) drawChart() } }) } // 绘制图表 function drawChart () { var dom1 = document.getElementById('chart-' + rnd1) var dom2 = document.getElementById('chart-' + rnd2) dom1.setAttribute('data-option', JSON.stringify(option1)) dom2.setAttribute('data-option', JSON.stringify(option2)) dom1.setAttribute('data-theme', 'macarons') dom2.setAttribute('data-theme', 'macarons') echarts.init(dom1, 'macarons').setOption(option1) echarts.init(dom2, 'macarons').setOption(option2) } })()