Echarts 柱狀圖上方顯示值


使用官網的例子,只不過加了itemStyle屬性

<!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts</title> </head> <body> <!-- 為ECharts准備一個具備大小(寬高)的Dom --> <div id="main" style="width:900px;height:300px"></div> <!-- ECharts單文件引入 --> <script src="http://echarts.baidu.com/build/dist/echarts.js"></script> <script type="text/javascript"> // 路徑配置 require.config({ paths: { echarts: 'http://echarts.baidu.com/build/dist' } }); // 使用 require( [ 'echarts', 'echarts/chart/bar' // 使用柱狀圖就加載bar模塊,按需加載 ], function(ec) { // 基於准備好的dom,初始化echarts圖表 var myChart = ec.init(document.getElementById('main')); var option = { tooltip: { show: true }, legend: { data: ['銷量'] }, xAxis: [{ type: 'category', data: ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"] }], yAxis: [{ type: 'value' }], series: [{ "name": "銷量", "type": "bar", "data": [5, 20, 40, 10, 10, 20], itemStyle: { normal: { label: { show: true, //開啟顯示 position: 'top', //在上方顯示 textStyle: { //數值樣式 color: 'black', fontSize: 16 } } } }, }] }; // 為echarts對象加載數據 myChart.setOption(option); } ); </script> </body>

 

顯示的效果如下
在這里插入圖片描述


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM