Use of echart.js

Project requirements, need such a histogram

Based on the idea of ​​having a library, I chose, echart (the version used is 3.x, not 4.x)

The detailed code is as follows:

var myChart = echarts.init(document.getElementById('main'));
var
option = { title: { text: 'I am the title' , x: "center", textStyle: { color: 'red', //set the color of the title fontStyle: 'italic' , fontSize: 20, } }, tooltip: {}, legend: {     // data:['big item','regular item']
    //Note: the series type needs to correspond to this
    //There are two values ​​for the array type here, and the corresponding series type should also have two objects
}, xAxis: A }, yAxis: { type: 'category', data: [ 'Large Item 5', 'Large Item 4', 'Large Item 3', 'Large Item 2', 'Large Item 1', 'Regular Item 5', 'Regular Item 4', 'Regular Item 3' , 'General Item 2', 'General Item 1' ] }, series: [ { name: 'big project' , type: 'bar', data: [300, 100, 295, 23, 500, 349, 279, 87, 777, 800], itemStyle: { // Set the style of each histogram normal: { color: function(params) { if(params.dataIndex >4) { return "yellow"; }else { return "red"; } } } }, label: { // Set the style of the label, which is the number on the histogram normal: { show:true, position: 'right', textStyle: { color: "red" } } } } ] }; // Display the chart using the configuration items and data just specified. myChart.setOption(option);
  //Set the click event myChart.on(
'click', function(params) { console.log(params); });

The final implementation looks like this

There should be no legend, all prepare to make a div to display the lenged and complete the development of the interface.

This is the first time to use echart.js, there must be something wrong, please correct it slowly

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325946028&siteId=291194637