EChartsで棒グラフを表示する際に、X軸の目盛りの間から棒を表示させたいと考えているのですが、下記ソースコードだと画面のサイズによって、目盛りの表示する箇所が棒の真ん中から表示されてしまいます。X軸の目盛りを固定で表示する方法はないでしょうか?
xAxis.boundaryGapをtrueにするだけではだめでした。
javascript
1 xAxis: { 2 name: '時間', 3 type: 'category', 4 boundaryGap: true, 5 data: ['0:00','','', '3:00','','', '6:00','','', '9:00','','','12:00','','', '15:00','','', '18:00','','','21:00','','', '24:00'] 6 },
<!DOCTYPE html> <html style="height: 100%"> <head> <meta charset="utf-8"> </head> <body style="height: 100%; margin: 0"> <div id="container" style="height: 50%; min-height: 250px"></div> <div id="container2" style="height: 50%; min-height: 250px"></div> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script> <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=xfhhaTThl11qYVrqLZii6w8qE5ggnhrY&__ec_v__=20190126"></script> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script> <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script> <script type="text/javascript"> var dom = document.getElementById("container"); var myChart = echarts.init(dom); var app = {}; option = null; option = { xAxis: { name: '日付', type: 'category', boundaryGap: true, data: ['7/1', '7/2', '7/3', '7/4', '7/5', '7/6', '7/7'] }, yAxis: { name: '歩数', type: 'value', splitNumber: 6 }, visualMap: { top: 10, right: 10, pieces: [{ gt: 0, lte: 10000, color: '#9FA8DA' },{ gt: 10000, color: '#1A237E' }], outOfRange: { color: '#999' } }, series: [{ data: [12000, 2140, 651, 8001, 24558, 11009, 8941], type: 'bar', markPoint: { data: [ {type: 'max', name: '最大值', itemStyle: {color: '#1A237E'}}, {type: 'min', name: '最小值', itemStyle: {color: '#9FA8DA'}} ] }, markLine: { silent: true, data:[{yAxis: 10000}], lineStyle: {shadowColor: '#0000D0'}, symbol:'none' }, label: { normal: { show: true, position: 'inside' } }, }] }; ; if (option && typeof option === "object") { myChart.setOption(option, true); } var dom2 = document.getElementById("container2"); var myChart2 = echarts.init(dom2); var app2 = {}; option2 = null; option2 = { tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, xAxis: { name: '時間', type: 'category', boundaryGap: true, data: ['0:00','','', '3:00','','', '6:00','','', '9:00','','','12:00','','', '15:00','','', '18:00','','','21:00','','', '24:00'] }, yAxis: { name: '(分)', type: 'value', splitNumber: 6, splitLine: { show: true }, axisTick: {alignWithLabel: true, interval: 25 } }, series: [{ data: [4500, 1000,300,5007,1200,2000,450,430,5400,2000,300,1790,2800,800,300,5700,5600,440,230,130,3200,340,4500,200], type: 'bar', markPoint: { data: [ {type: 'max', name: '最大值', itemStyle: {color: '#1A237E'}}, {type: 'min', name: '最小值', itemStyle: {color: '#C5CAE9'}}, ] } } ] }; ; if (option2 && typeof option2 === "object") { myChart2.setOption(option2, true); } window.onresize = function () { if(window.innerWidth > 600 && window.innerHeight > 500){ myChart.resize({ width: window.innerWidth, height: window.innerHeight / 2, silent: false }); myChart2.resize({ width: window.innerWidth, height: window.innerHeight / 2, silent: false }); }else if(window.innerWidth > 600 && window.innerHeight <= 500){ myChart.resize({ width: window.innerWidth, height: 250, silent: false }); myChart2.resize({ width: window.innerWidth, height: 250, silent: false }); }else if(window.innerWidth <= 600 && window.innerHeight > 500){ myChart.resize({ width: 600, height: window.innerHeight / 2, silent: false }); myChart2.resize({ width: 600, height: window.innerHeight / 2, silent: false }); }else{ } }; </script> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/21 01:18