chartTrendRender.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. <template>
  2. <div class="chart-trend-render">
  3. <div class="header">
  4. <template v-if="chart_type===1">
  5. <!-- <el-button
  6. type="primary"
  7. v-for="item in yearSelector"
  8. :key="item.value"
  9. size="mini"
  10. :plain="item.value !== year_select"
  11. class="year-btn"
  12. @click.native="changeYear(item)"
  13. >{{ item.name }}</el-button
  14. > -->
  15. <el-popover
  16. placement="bottom"
  17. trigger="click"
  18. popper-class="btn-select-popover"
  19. width="460" style="display: inline-block;">
  20. <div class="btn-wrap">
  21. <el-button
  22. type="primary"
  23. v-for="item in yearSelector"
  24. :key="item.value"
  25. size="mini"
  26. :plain="item.value !== year_select"
  27. class="year-btn"
  28. @click.native="changeYear(item)"
  29. >{{ item.name }}</el-button>
  30. </div>
  31. <el-button type="primary" plain size="mini" class="year-btn" slot="reference" style="margin-right:15px;background-color: #e6eefb;color:#0052D9;">{{$t('Chart.time_interval')}}</el-button>
  32. </el-popover>
  33. <el-button type="primary" plain size="mini" class="btn-sty" @click="openDateDia">{{
  34. dateTip
  35. }}</el-button>
  36. <el-button type="primary" plain size="mini" class="btn-sty" @click="showOnChart('toggle')" v-if="!isOnlyShowBaseChart&&isShowChartBasis">
  37. <!-- <i class="el-icon-view"></i> -->
  38. {{ isShowOnyearData ? $t('Edb.hide_yearonyear') : $t('Edb.show_yearonyear')}}
  39. </el-button>
  40. </template>
  41. <!-- 季节图时间选择 -->
  42. <!-- <template v-else-if="chart_type===2">
  43. <date-picker
  44. v-model="season_year"
  45. type="month"
  46. value-type="format"
  47. range
  48. placeholder="年份日期选择"
  49. @change="getDataByPath"
  50. />
  51. </template> -->
  52. <div v-else-if="chart_type === 2" @click="openDateDia" class="date-setting">
  53. {{ season_year && season_year.length>0 ? season_year[0]+'~'+season_year[1]:"年份日期选择" }}
  54. </div>
  55. <el-button type="primary" plain size="mini" class="btn-sty" style="margin-left:auto;"
  56. @click="chartTypeChange" v-if="!isOnlyShowBaseChart&&isAllowSwitchSeason">
  57. <i class="el-icon-sort" style="transform: rotate(90deg);"></i>
  58. {{chart_type==1?$t('Edb.switch_season'):$t('Edb.switch_curve')}}
  59. </el-button>
  60. </div>
  61. <div class="min-wrapper">
  62. <div class="chartWrapper" id="chartWrapper" v-if="showChart">
  63. <Chart :options="options" :chartInfo="chartInfo" ref="chartRef"/>
  64. <div class="range-cont left" v-if="leftIndex != -1">
  65. <el-input
  66. style="width: 80px; display: block"
  67. size="mini"
  68. type="number"
  69. placeholder="上限"
  70. :disabled="!isAllowEditLimit"
  71. v-model="chartInfo.MaxValue"
  72. @change="() => { chart_type===1?setOptions():setSeasonOptions() }"
  73. />
  74. <el-input
  75. class="min-data-input"
  76. size="mini"
  77. type="number"
  78. placeholder="下限"
  79. :disabled="!isAllowEditLimit"
  80. v-model="chartInfo.MinValue"
  81. @change="() => { chart_type===1?setOptions():setSeasonOptions() }"
  82. />
  83. </div>
  84. <div class="range-cont right" v-if="isShowOnyearData">
  85. <el-input
  86. style="width: 80px; display: block"
  87. size="mini"
  88. type="number"
  89. placeholder="上限"
  90. v-model="limitData.rightMax"
  91. :disabled="!isAllowEditLimit"
  92. @change="changeLimit"
  93. />
  94. <el-input
  95. class="min-data-input"
  96. size="mini"
  97. type="number"
  98. placeholder="下限"
  99. v-model="limitData.rightMin"
  100. :disabled="!isAllowEditLimit"
  101. @change="changeLimit"
  102. />
  103. </div>
  104. <!-- 公历农历切换 只用于季节性图 -->
  105. <div style="text-align:center;">
  106. <el-radio-group
  107. v-model="calendar_type"
  108. class="calendar-cont"
  109. v-if="chart_type===2"
  110. @change="getDataByPath"
  111. >
  112. <el-radio-button label="公历">{{$t('Chart.calendar_gre')}}</el-radio-button>
  113. <el-radio-button label="农历">{{$t('Chart.calendar_lunar')}}</el-radio-button>
  114. </el-radio-group>
  115. </div>
  116. </div>
  117. <img src="~@/assets/img/icons/edb-stopping.png" class="stop-mark" v-if="([2,34].includes(chartInfo.Source) || chartInfo.EdbType==2) && chartInfo.NoUpdate==1" />
  118. </div>
  119. <div class="table-data">
  120. </div>
  121. <!-- 自定义时间段选择弹窗 -->
  122. <DateChooseDia
  123. :isDateDia="isDateDia"
  124. :dateForm="dateForm"
  125. @cancel="isDateDia = false"
  126. @dateBack="dataChangeBack"
  127. />
  128. </div>
  129. </template>
  130. <script>
  131. import { dataBaseInterface } from '@/api/api.js';
  132. import * as supplyApi from '@/api/modules/supplyApi.js';
  133. import { yearSelector,defaultOpts,seasonOptions } from '@/utils/defaultOptions'
  134. import Chart from '../components/chart'
  135. import DateChooseDia from '../components/DateChooseDia';
  136. import Highcharts from 'highcharts'
  137. export default {
  138. components: { Chart,DateChooseDia },
  139. props: {
  140. edbid: {
  141. type: Number,
  142. },
  143. // 语言 ch/en
  144. chartLang:{
  145. type: String,
  146. default:()=> 'zh'
  147. },
  148. isShowChartBasis:{
  149. type:Boolean,
  150. default:false
  151. },
  152. isAllowSwitchSeason:{
  153. type:Boolean,
  154. default:false
  155. },
  156. isAllowEditLimit:{
  157. type:Boolean,
  158. default:false
  159. }
  160. },
  161. computed: {
  162. // 同比,环比,环差,超季节性、 残差展示基础图
  163. //ETA1.1.1 所有的计算指标都能展示季节性图
  164. isOnlyShowBaseChart() {
  165. /* return [6,12,13,35,37].includes(this.chartInfo.Source) */
  166. return false
  167. }
  168. },
  169. watch: {
  170. edbid:{
  171. handler(newVal){
  172. if(newVal){
  173. this.init()
  174. this.chart_type = 1
  175. this.isShowOnyearData = false
  176. this.getDataByPath()
  177. }
  178. },
  179. immediate:true
  180. }
  181. },
  182. data () {
  183. return {
  184. year_select: 10, //年份选择项 默认全部
  185. yearSelector:[
  186. {
  187. name: /* '全部' */this.$t('Chart.time_all'),
  188. value: 10,
  189. },
  190. ...yearSelector,
  191. ],
  192. select_date: [], // 自定义时间段项
  193. options: {},
  194. showChart: false,
  195. chart_type: 1,// 1曲线 2季节
  196. isShowOnyearData: false, //是否展示同比
  197. chartInfo: {},
  198. dataList: [],
  199. leftIndex: 0,
  200. season_year:[],//季节图日期选择
  201. calendar_type:'公历',
  202. /* 日期弹窗 */
  203. isDateDia: false, // 时间段弹窗
  204. dateForm: {},
  205. dateTip: /* '请选择时间段' */ this.$t('Chart.choose_time'),
  206. limitData: {
  207. letMin: 0,
  208. leftMax: 0,
  209. rightMin: 0,
  210. rightMax: 0,
  211. },
  212. oldOptions: {
  213. MinValue: 0,
  214. MaxValue: 0
  215. },
  216. // 最近几年
  217. count_year:'',
  218. };
  219. },
  220. methods: {
  221. getDataByPath() {
  222. const apiMap = {
  223. '/database': this.getEdbData,
  224. '/analyseVariety': this.getPlantEdbData
  225. }
  226. apiMap[this.$route.path]()
  227. },
  228. /* 获取指标所有数据 */
  229. async getEdbData() {
  230. let params = {
  231. EdbInfoId: this.edbid,
  232. DateType: this.year_select,
  233. StartYear:this.count_year || 0,
  234. StartDate: this.select_date[0] || '',
  235. EndDate: this.select_date[1] || ''
  236. }
  237. const res = this.chart_type === 1
  238. ? await dataBaseInterface.ebd_data(params)
  239. : await dataBaseInterface.ebdSeasonData({
  240. EdbInfoId: this.edbid,
  241. DateType: this.year_select,
  242. Calendar: this.calendar_type,
  243. StartYear:this.count_year || 0,
  244. StartDate: this.season_year[0] || '',
  245. EndDate: this.season_year[1] || '',
  246. })
  247. if(res.Ret !== 200) return
  248. const { DataList,EdbInfo } = res.Data;
  249. // DataList 表格数据列表
  250. this.chartInfo = (this.oldOptions.MinValue || this.oldOptions.MaxValue) ? {
  251. ...EdbInfo,
  252. ...this.oldOptions
  253. } : EdbInfo;
  254. this.tableData = DataList || [];
  255. if(this.chart_type==2 && !(this.season_year && this.season_year.length>0)){
  256. // 第一次进行初始化显示
  257. let latestYear = parseInt(this.chartInfo.LatestDate.substring(0,4))
  258. this.season_year = [`${latestYear-this.count_year+1}-01-01`,`${latestYear}-12-31`];
  259. }
  260. this.chart_type === 1 ? this.setOptions() : this.setSeasonOptions();
  261. this.showChart = true;
  262. this.$nextTick(()=>{
  263. if(!EdbInfo.ChartImage){
  264. //设置图表缩略图
  265. this.saveEdbImg(EdbInfo)
  266. }
  267. })
  268. },
  269. // 切换刷新状态
  270. toggleEdbRefreshStatusFun(){
  271. this.chartInfo.NoUpdate = 1-this.chartInfo.NoUpdate
  272. },
  273. //保存指标缩略图
  274. async saveEdbImg(EdbInfo){
  275. let svg = this.$refs.chartRef.chart.getSVG({
  276. chart: {
  277. width: 340,
  278. height: 230,
  279. },
  280. });
  281. let form = new FormData();
  282. form.append("Img", svg);
  283. let { Data,Ret } = await dataBaseInterface.uploadImgSvg(form);
  284. if(Ret!==200 || !Data) return
  285. await dataBaseInterface.saveEdbChartImg({
  286. EdbInfoId: EdbInfo.EdbInfoId,
  287. ImageUrl: Data.ResourceUrl,
  288. });
  289. },
  290. /* 获取装置指标数据 */
  291. async getPlantEdbData() {
  292. let params = {
  293. VarietyEdbId: this.edbid,
  294. DateType: this.year_select,
  295. StartYear:this.count_year || 0,
  296. StartDate: this.select_date[0] || '',
  297. EndDate: this.select_date[1] || ''
  298. }
  299. const res = this.chart_type === 1
  300. ? await supplyApi.getEdbDetailData(params)
  301. : await supplyApi.getEdbSeasonData({
  302. VarietyEdbId: this.edbid,
  303. DateType: this.year_select,
  304. Calendar: this.calendar_type,
  305. StartYear:this.count_year || 0,
  306. StartDate: this.season_year[0] || '',
  307. EndDate: this.season_year[1] || '',
  308. })
  309. if(res.Ret !== 200) return
  310. const { DataList,EdbInfo } = res.Data;
  311. // DataList 表格数据列表
  312. this.chartInfo = (this.oldOptions.MinValue || this.oldOptions.MinValue) ? {
  313. ...EdbInfo,
  314. ...this.oldOptions
  315. } : EdbInfo;
  316. this.tableData = DataList || [];
  317. if(this.chart_type==2 && !(this.season_year && this.season_year.length>0)){
  318. // 第一次进行初始化显示
  319. let latestYear = parseInt(this.chartInfo.LatestDate.substring(0,4))
  320. this.season_year = [`${latestYear-this.count_year+1}-01-01`,`${latestYear}-12-31`];
  321. }
  322. this.chart_type === 1 ? this.setOptions() : this.setSeasonOptions();
  323. this.showChart = true;
  324. },
  325. /* 年份改变 重新刷新图表接口 保存当前的图表配置和上下限 只改变图表 */
  326. changeYear(item) {
  327. this.year_select = item.value;
  328. this.select_date = [];
  329. this.dateTip = /* '请选择时间段' */ this.$t('Chart.choose_time');
  330. const { MinValue,MaxValue } = this.chartInfo;
  331. this.oldOptions = {
  332. MinValue: Number(MinValue),
  333. MaxValue: Number(MaxValue)
  334. }
  335. this.getDataByPath()
  336. },
  337. /* 打开时间段弹窗 */
  338. openDateDia() {
  339. // 自定义时间段回显
  340. let selectDateStart = this.chart_type === 2?this.season_year[0]:this.select_date[0]
  341. let selectDateEnd = this.chart_type === 2?this.season_year[1]:this.select_date[1]
  342. this.dateForm = {
  343. date_type: this.year_select,
  344. start_date:
  345. this.year_select === 5 || this.year_select === 6
  346. ? selectDateStart
  347. : '',
  348. end_date: this.year_select === 5 ? selectDateEnd : '',
  349. count_year: this.year_select === 20 ? this.count_year : ''
  350. };
  351. this.isDateDia = true;
  352. },
  353. /* 保存完自定义日期 刷新数据 保存当前的图表配置和上下限 只改变图表*/
  354. dataChangeBack(data) {
  355. this.year_select = data.dateType;
  356. this.isDateDia = false;
  357. this.select_date = [data.start_date, data.end_date];
  358. this.count_year = data.count_year
  359. this.dateTip =
  360. data.dateType === 5
  361. ? `${data.start_date}~${data.end_date}`
  362. : data.dateType === 6
  363. ?/* `${data.start_date}~至今` */ this.$t('Chart.data_tip_since',{date:data.start_date})
  364. :/* `最近${this.count_year}年` */ this.$t('Chart.date_tip_count',{year:this.count_year})
  365. if(this.chart_type === 2){
  366. let latestYear = parseInt(this.chartInfo.LatestDate.substring(0,4))
  367. let dateStart = data.start_date
  368. let dateEnd = data.end_date
  369. if(data.dateType==20){
  370. dateStart = `${latestYear-this.count_year+1}-01-01`
  371. dateEnd = `${latestYear}-12-31`
  372. }else if(data.dateType==6){
  373. dateEnd = this.chartInfo.LatestDate
  374. }
  375. this.season_year = [dateStart, dateEnd];
  376. }
  377. const { MinValue,MaxValue } = this.chartInfo;
  378. this.oldOptions = {
  379. MinValue,
  380. MaxValue
  381. }
  382. this.getDataByPath();
  383. },
  384. chartTypeChange() {
  385. this.chart_type = this.chart_type===1 ? 2 : 1;
  386. this.init('no_reset')
  387. this.getDataByPath();
  388. },
  389. // 展示同比图
  390. async showOnChart(scene='') {
  391. if(scene==='toggle') {
  392. this.isShowOnyearData = this.isShowOnyearData ? false : true;
  393. if(!this.isShowOnyearData){
  394. const { MinValue,MaxValue } = this.chartInfo;
  395. this.oldOptions = {
  396. MinValue: Number(MinValue),
  397. MaxValue: Number(MaxValue)
  398. }
  399. this.getDataByPath();
  400. }
  401. }
  402. if(!this.isShowOnyearData) return;
  403. let params = {
  404. DateType: this.year_select,
  405. StartDate: this.select_date[0] || '',
  406. EndDate: this.select_date[1] || ''
  407. }
  408. const res = this.$route.path === '/analyseVariety'
  409. ? await supplyApi.getEdbOnyearData({VarietyEdbId:this.edbid,...params})
  410. : await dataBaseInterface.edbOnyearData({EdbInfoId: this.edbid,...params});
  411. if(res.Ret !== 200) return
  412. const { EdbInfo,DataList } = res.Data;
  413. if(!this.limitData.rightMin && !this.limitData.rightMax) {
  414. this.limitData.rightMin = Number(EdbInfo.MinValue);
  415. this.limitData.rightMax = Number(EdbInfo.MaxValue);
  416. }
  417. this.options.yAxis.push({
  418. title: {
  419. text: '',
  420. align: 'high',
  421. rotation: 0,
  422. y: -15,
  423. offset: 0
  424. },
  425. labels: {
  426. formatter: function (ctx) {
  427. return ctx.value;
  428. },
  429. align: 'center',
  430. },
  431. min: Number(this.limitData.rightMin),
  432. max: Number(this.limitData.rightMax),
  433. ...seasonOptions.yAxis,
  434. opposite: true,
  435. })
  436. this.options.series.push({
  437. data: DataList.map(item=>([item.DataTimestamp, item.Value])),
  438. type: 'spline',
  439. yAxis: 1,
  440. name: this.chartLang=='zh'?`${EdbInfo.EdbName}同比`:EdbInfo.EdbNameEn?`${EdbInfo.EdbNameEn}同比`:'无英文名称',
  441. lineWidth: 1
  442. })
  443. console.log(this.options.series)
  444. },
  445. changeLimit() {
  446. const { rightMax,rightMin } = this.limitData;
  447. this.options.yAxis[1].max = Number(rightMax);
  448. this.options.yAxis[1].min = Number(rightMin);
  449. },
  450. /* 图表配置 曲线*/
  451. setOptions() {
  452. const chartData = _.cloneDeep(this.tableData);
  453. //拼接标题 数据列
  454. let data = [],
  455. ydata = [];
  456. //y轴
  457. // 单位 中文时 为无不显示 英文时 为空提示点击输入
  458. // 中文不存在或等于无时 英文显示为空 中文存在且英文不存在时 显示'英文单位'
  459. let yTitleText = this.chartLang=='zh'?
  460. (this.chartInfo.Unit && this.chartInfo.Unit!='无') ? this.chartInfo.Unit:'':
  461. !this.chartInfo.UnitEn && this.chartInfo.Unit && this.chartInfo.Unit!='无' ? '英文单位':this.chartInfo.UnitEn
  462. // title样式 英文为空时,提示文字样式 英文可以点击设置
  463. let yTitleStyle = {}
  464. if(this.chartLang=='en'){
  465. yTitleStyle.cursor='pointer'
  466. if(yTitleText=='英文单位'){
  467. yTitleStyle.color="#999"
  468. }
  469. }
  470. let yItem = {
  471. title: {
  472. text: yTitleText,
  473. align: 'high',
  474. rotation: 0,
  475. y: -12,
  476. x: 0,
  477. textAlign: 'left',
  478. reserveSpace: false,
  479. style:yTitleStyle
  480. },
  481. labels: {
  482. formatter: function (ctx) {
  483. return ctx.value;
  484. },
  485. align: 'center',
  486. },
  487. min: Number(this.chartInfo.MinValue),
  488. max: Number(this.chartInfo.MaxValue),
  489. ...seasonOptions.yAxis,
  490. };
  491. // 图例名称和图例文字样式
  492. let dataName = this.chartLang=='zh'?this.chartInfo.EdbName:this.chartInfo.EdbNameEn?this.chartInfo.EdbNameEn:'无英文名称'
  493. let color = this.chartLang=='en'&&(!this.chartInfo.EdbNameEn)?'#999':'#333'
  494. let legend={
  495. ...defaultOpts.legend,
  496. itemStyle: {
  497. color
  498. },
  499. }
  500. //数据列
  501. let obj = {
  502. data: [],
  503. type: 'spline',
  504. yAxis: 0,
  505. name: dataName,
  506. lineWidth: 3
  507. };
  508. chartData.forEach((item, index) => {
  509. obj.data.push([item.DataTimestamp, item.Value]);
  510. });
  511. data.push(obj);
  512. ydata.push(yItem);
  513. // 范围为1年内 x轴显示为月/日 否则默认年/月
  514. let xAxis = {};
  515. const bool_time = this.xTimeDiffer();
  516. xAxis = bool_time
  517. ? {
  518. ...defaultOpts.xAxis,
  519. labels: {
  520. formatter: function (ctx) {
  521. return Highcharts.dateFormat('%m/%d', ctx.value);
  522. },
  523. },
  524. }
  525. : {
  526. ...defaultOpts.xAxis,
  527. labels: {
  528. formatter: function (ctx) {
  529. return Highcharts.dateFormat('%y/%m', ctx.value);
  530. },
  531. },
  532. };
  533. this.options = {
  534. series: data,
  535. yAxis: ydata,
  536. xAxis,
  537. legend
  538. };
  539. this.showOnChart();
  540. },
  541. /* 季节图 */
  542. setSeasonOptions() {
  543. console.log(this.tableData)
  544. const chartData = _.cloneDeep(this.tableData);
  545. let seasonYdata = [],
  546. seasonData = [];
  547. /* 公历数据处理 处理数据列 y轴 */
  548. if (this.calendar_type === '公历')
  549. for (let j of chartData) {
  550. let serie_item = {
  551. data: [],
  552. type: 'spline',
  553. yAxis: 0,
  554. name: j.Year,
  555. };
  556. const data_array = this.calendar_type === '农历'?_.cloneDeep(j.Items):_.cloneDeep(j.DataList);
  557. data_array &&
  558. data_array.forEach((item) => {
  559. serie_item.data.push([item.DataTimestamp, item.Value]);
  560. });
  561. const index = chartData.findIndex(
  562. (item) => item.Year === j.Year
  563. );
  564. const s_yItem = {
  565. labels: {
  566. align: 'center',
  567. },
  568. title: {
  569. text: this.chartLang=='zh'?this.chartInfo.Unit:
  570. !this.chartInfo.UnitEn && this.chartInfo.Unit && this.chartInfo.Unit!='无' ? '英文单位':this.chartInfo.UnitEn,
  571. align: 'high',
  572. rotation: 0,
  573. y: -12,
  574. x: 0,
  575. textAlign: 'left',
  576. reserveSpace: false,
  577. },
  578. max: Number(this.chartInfo.MaxValue),
  579. min: Number(this.chartInfo.MinValue),
  580. ...seasonOptions.yAxis,
  581. visible: index===0
  582. };
  583. seasonData.push(serie_item);
  584. seasonYdata.push(s_yItem);
  585. }
  586. /* 农历数据处理 */
  587. let filterArr =
  588. this.calendar_type === '农历'
  589. ? chartData.List.filter((item, index) => index > 0)
  590. : [];
  591. if (this.calendar_type === '农历')
  592. for (let j of filterArr) {
  593. let serie_item = {
  594. data: [],
  595. type: 'spline',
  596. yAxis: 0,
  597. name: j.Year
  598. };
  599. const data_array = _.cloneDeep(j.Items);
  600. data_array &&
  601. data_array.forEach((item) => {
  602. serie_item.data.push([item.DataTimestamp, item.Value]);
  603. });
  604. const index = filterArr.findIndex((item) => item.Year === j.Year);
  605. const s_yItem = {
  606. labels: {
  607. align: 'center',
  608. },
  609. title: {
  610. text: this.chartLang=='zh'?this.chartInfo.Unit:
  611. !this.chartInfo.UnitEn && this.chartInfo.Unit && this.chartInfo.Unit!='无' ? '英文单位':this.chartInfo.UnitEn,
  612. align: 'high',
  613. rotation: 0,
  614. y: -12,
  615. x: 0,
  616. textAlign: 'left',
  617. reserveSpace: false,
  618. },
  619. max: Number(this.chartInfo.MaxValue),
  620. min: Number(this.chartInfo.MinValue),
  621. ...seasonOptions.yAxis,
  622. visible: index===0
  623. };
  624. seasonData.push(serie_item);
  625. seasonYdata.push(s_yItem);
  626. }
  627. /* x轴显示月日 提示框显示月日*/
  628. defaultOpts.xAxis.labels = {
  629. formatter: function () {
  630. return Highcharts.dateFormat('%m/%d', this.value);
  631. },
  632. };
  633. const tooltip = {
  634. ...defaultOpts.tooltip,
  635. dateTimeLabelFormats: {
  636. // 时间格式化字符
  637. day: '%m/%d',
  638. week: '%m/%d',
  639. month: '%m/%d',
  640. year: '%m/%d',
  641. },
  642. xDateFormat: '%m/%d',
  643. }
  644. let rangeSelector =
  645. this.calendar_type === '农历'
  646. ? {
  647. enabled: true,
  648. selected: 0,
  649. inputStyle: {
  650. display: 'none',
  651. },
  652. labelStyle: {
  653. display: 'none',
  654. },
  655. buttonTheme: {
  656. style: {
  657. display: 'none',
  658. },
  659. },
  660. buttons: [
  661. {
  662. type: 'month',
  663. count: 12,
  664. text: '12月',
  665. },
  666. {
  667. type: 'month',
  668. count: 15,
  669. text: '15月',
  670. },
  671. {
  672. type: 'all',
  673. text: '全部',
  674. type: 'all',
  675. },
  676. ],
  677. }
  678. : {
  679. enabled: false,
  680. };
  681. this.options = {
  682. colors:
  683. this.calendar_type === '公历'
  684. ? seasonOptions.colors.slice(-chartData.length)
  685. : seasonOptions.colors.slice(-filterArr.length),
  686. series: seasonData,
  687. yAxis: seasonYdata,
  688. rangeSelector,
  689. tooltip
  690. };
  691. console.log(this.options)
  692. },
  693. /* 查询范围为1年内 x轴显示为月/日 否则默认年/月 */
  694. xTimeDiffer() {
  695. const end_date =
  696. this.year_select === 5
  697. ? this.select_date[1]
  698. : this.year_select === 6
  699. ? new Date()
  700. : '';
  701. //年限差
  702. const year_differ = this.$moment(end_date).diff(
  703. this.$moment(this.select_date[0]),
  704. 'years',
  705. true
  706. );
  707. // console.log(year_differ)
  708. if ([5, 6].includes(this.year_select) && year_differ <= 1) {
  709. return true;
  710. } else {
  711. return false;
  712. }
  713. },
  714. init(type='') {
  715. if(type!=='no_reset') this.chart_type = 1;
  716. this.isShowOnyearData = false;
  717. this.year_select = this.chart_type==1 ? 10 : 20;
  718. // 季节性图默认展示最近5年数据
  719. this.count_year=5
  720. this.select_date = [];
  721. this.options = {};
  722. this.dateTip = /* '请选择时间段' */ this.$t('Chart.choose_time');
  723. this.oldOptions = {};
  724. this.calendar_type = '公历';
  725. this.season_year = [];
  726. this.limitData = {
  727. letMin: 0,
  728. leftMax: 0,
  729. rightMin: 0,
  730. rightMax: 0,
  731. }
  732. },
  733. // 编辑英文信息弹窗
  734. editEnName(){
  735. this.$emit('editEnName','chart')
  736. },
  737. // 竖轴标题点击事件
  738. clickYAxisTitle(){
  739. console.log(this.chartLang);
  740. if(this.chartLang == 'en') this.editEnName()
  741. }
  742. },
  743. created() {},
  744. mounted() {},
  745. }
  746. </script>
  747. <style lang='scss'>
  748. .chart-trend-render {
  749. width:100%;
  750. box-sizing: border-box;
  751. overflow-x: hidden;
  752. @media screen and (min-width: 1711px) {
  753. .min-data-input { margin-top: 300px; }
  754. }
  755. @media screen and (max-width:1710px) {
  756. .min-data-input { margin-top: 210px; }
  757. }
  758. .header {
  759. display: flex;
  760. position: relative;
  761. .year-btn,.btn-sty {
  762. min-width: 98px;
  763. font-size: 14px;
  764. margin-right: 5px;
  765. margin-bottom: 5px;
  766. }
  767. .btn-sty {
  768. background-color: #fff;
  769. color: #0052D9;
  770. }
  771. .date-setting{
  772. width: 210px;
  773. // height: 40px;
  774. padding: 10px;
  775. border: 1px solid #DCDFE6;
  776. border-radius: 4px;
  777. cursor: pointer;
  778. font-size: 14px;
  779. color: #333333;
  780. box-sizing: border-box;
  781. }
  782. .change-chart-btn{
  783. float: right;
  784. color: #409eff;
  785. font-size: 16px;
  786. cursor: pointer;
  787. &::before{
  788. content:'';
  789. display: inline-block;
  790. width: 18px;
  791. height: 18px;
  792. background-image: url('~@/assets/img/chart_m/change.png');
  793. background-size: cover;
  794. position: relative;
  795. top: 4px;
  796. right: 4px;
  797. }
  798. }
  799. }
  800. .min-wrapper {
  801. position: relative;
  802. .el-input__inner {
  803. padding: 0 0 0 5px;
  804. }
  805. /* margin: 20px 0 0 0; */
  806. min-height: 320px;
  807. .chartWrapper {
  808. position: relative;
  809. padding: 0 105px 0 100px;
  810. .range-cont {
  811. position: absolute;
  812. top: 8%;
  813. .min-data-input {
  814. width: 80px;
  815. display: block;
  816. }
  817. &.left {
  818. left: 0px;
  819. }
  820. &.right {
  821. right: 0;
  822. }
  823. }
  824. }
  825. .stop-mark{
  826. height: 48px;
  827. width: 48px;
  828. position: absolute;
  829. right: 0;
  830. top: 0;
  831. pointer-events: none;
  832. }
  833. }
  834. }
  835. </style>