隐藏

echarts柱状图

发布:2024/11/26 19:53:48作者:管理员 来源:本站 浏览次数:105

import * as echarts from 'echarts';

var app = {};

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

option = {
  legend: {},
  tooltip: {},
  dataset: {
    dimensions: ['product', '2015', '2016', '2017'],
    source: [
      { product: 'Matcha Latte', 2015: 43.3, 2016: 85.8, 2017: 93.7 },
      { product: 'Milk Tea', 2015: 83.1, 2016: 73.4, 2017: 55.1 },
      { product: 'Cheese Cocoa', 2015: 86.4, 2016: 65.2, 2017: 82.5 },
      { product: 'Walnut Brownie', 2015: 72.4, 2016: 53.9, 2017: 39.1 }
    ]
  },
  xAxis: { type: 'category' },
  yAxis: {},
  // Declare several bar series, each will be mapped
  // to a column of dataset.source by default.
  series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]
};

option && myChart.setOption(option);

+++++++++++++++++++++++++++++++++++++++++++++++++

OutSystems-js

let chart1Container = window.document.querySelector("#Chart5");
let chart1 = echarts.init(chart1Container);
chart1.clear();
let jsonarr = JSON.parse($parameters.JsonStr);
var origins = []
jsonarr.forEach(a=>{
    origins.push(a.Modality);
})

var series_data = []
jsonarr.forEach(a=>{
    if(a.TotalMethodSum==1){
        series_data.push({value:a.TotalMethodSum,itemStyle:{color:'#a90000'}});
    }else{
        series_data.push(a.TotalMethodSum);
    }
   
})

//let xAxisData = [...new Set(origins.map(s => s.PG))];
//xAxisData = xAxisData.sort();
option = {
  legend: {},
  tooltip: {},
  dataset: {
    source: [
      ['product', '2015', '2016', '2017'],
      ['Matcha Latte', 43.3, 85.8, 93.7],
      ['Milk Tea', 83.1, 73.4, 55.1],
      ['Cheese Cocoa', 86.4, 65.2, 82.5],
      ['Walnut Brownie', 72.4, 53.9, 39.1]
    ]
  },
  xAxis: { type: 'category' },
  yAxis: {},
  // Declare several bar series, each will be mapped
  // to a column of dataset.source by default.
  series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]
};

chart1.setOption(option);

 chart1.on('click',(param)=>{
   alert(param.name);
   alert(param.seriesName);
   for(var i = param.dataIndex;i>=0;--i){
     if(xAxisGroupData[i] !== ""){
       alert(xAxisGroupData[i]);
       break;
     }
   }
   //alert(param.dataIndex);
});