/** * 财务分析:净利润/资产单图 + 页签切换。 * 数据来源:StockFinanceGuide.ascx 输出的 cwfxData1/cwfxData2 JSON。 */ (function () { 'use strict'; document.addEventListener('DOMContentLoaded', function () { var colors = ['#F2B84B', '#2F6FBF']; var box = document.getElementById('cwfx_echarts'); var tabs = document.getElementById('cwfxTabs'); var legend = document.getElementById('cwfxLegend'); if (!box || typeof window.DualAxisChart !== 'function') { return; } function read(id) { var el = document.getElementById(id); if (!el) { return null; } try { return JSON.parse(el.textContent || el.innerText); } catch (err) { return null; } } var sets = { profit: read('cwfxData1'), asset: read('cwfxData2') }; var order = []; if (sets.profit) { order.push('profit'); } if (sets.asset) { order.push('asset'); } if (!order.length) { return; } var active = order[0]; var chart = null; function paintLegend(series) { if (!legend) { return; } legend.innerHTML = ''; for (var i = 0; i < series.length; i++) { var row = document.createElement('li'); var dot = document.createElement('i'); dot.className = 'c' + (i + 1); var name = document.createElement('span'); name.textContent = series[i].name; row.appendChild(dot); row.appendChild(name); legend.appendChild(row); } } function paint() { var data = sets[active]; if (!data) { return; } if (chart) { chart.destroy(); } chart = new window.DualAxisChart('cwfx_echarts', { xAxisData: data.xAxisData, series: data.series, colors: colors, smooth: true, showLegend: false, singleAxis: active === 'asset', yAxisNames: active === 'asset' ? ['金额(亿元)'] : ['归属净利润(亿元)', '同比(%)'], negativeColor: '#9db7d5', zeroLine: true }); paintLegend(data.series); if (tabs) { var links = tabs.getElementsByTagName('a'); for (var i = 0; i < links.length; i++) { links[i].className = links[i].getAttribute('data-tab') === active ? 'cur' : ''; } } } if (tabs && tabs.getElementsByTagName('a').length > 1) { tabs.addEventListener('click', function (event) { var link = event.target; while (link && link.tagName !== 'A') { link = link.parentNode; } if (!link) { return; } event.preventDefault(); var key = link.getAttribute('data-tab'); if (!sets[key] || key === active) { return; } active = key; paint(); }); } else if (tabs) { tabs.className = 'finance-tabs is-hidden'; } paint(); }); }());