簡體   English   中英

有沒有辦法在條形圖中的每個條形圖上方顯示一條線?

[英]Is there a way to show a line above each bar in a bar chart?

我有一個條形圖,我想在條形上方顯示一條水平線以指示峰值。 有沒有辦法在不使用自定義渲染器的情況下使用echarts實現這一點?

 var myChart = echarts.init(document.getElementById('main')); option = { "series": [ { "type": "bar", "dimensions": [ "date", "percent", "tooltip" ], "color": "#1976d2", "data": [ [ "2023-01-11", 3.230555555555555, "3.2" ], [ "2023-01-12", 5.436111111111111, "5.4" ], [ "2023-01-13", 7.306481481481481, "7.3" ], ], "name": "Mean", }, { "type": "custom", "dimensions": [ "date", "peak", "tooltip" ], "color": "#d32f2f", "renderItem": renderPeakLine, "data": [ [ "2023-01-11", 25, 25 ], [ "2023-01-12", 50, 50 ], [ "2023-01-13", 50, 50 ], ], "yAxisIndex": 0, "name": "Peak", } ], "xAxis": { "show": true, "type": "time", "axisLabel": {} }, "yAxis": { "show": true, "type": "value", "min": 0, "max": 100, "scale": false, }, "tooltip": { "show": true, "trigger": "axis", "axisPointer": { "label": {} } }, "legend": { "show": true } } const peakColor = '#d32f2f' function renderPeakLine(param, api) { const bandWidth = (param.coordSys.width / param.dataInsideLength) * 0.6 const point = api.coord([api.value(0), api.value(1)]) const value = api.value(2) // This skips drawing the red line for 0 if (value === 0) return return { type: 'line', transition: 'shape', z2: 10, shape: { x1: point[0] - bandWidth / 2, x2: point[0] + bandWidth / 2, y1: point[1], y2: point[1], }, style: api.style({ fill: null, stroke: api.visual('color'), lineWidth: 2, }), } } myChart.setOption(option);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.0.4/echarts.min.js"></script> <div id="main" style="width: 500px;height:200px;"></div>

您所描述的聽起來像是燭台圖表類型。

 var myChart = echarts.init(document.getElementById('main')); option = { xAxis: { data: ["2023-01-11", "2023-01-12", "2023-01-13"] }, yAxis: { show: true, type: "value", min: 0, max: 100, scale: false, }, series: [ { type: 'candlestick', data: [ [ 0, 3.230555555555555, 0, 25 ], [ 0, 5.436111111111111, 0, 50 ], [ 0, 7.306481481481481, 0, 50 ], ], } ] }; myChart.setOption(option);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.0.4/echarts.min.js"></script> <div id="main" style="width: 500px;height:200px;"></div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM