Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/layout/barGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ export function layout(seriesType, ecModel) {
var valueAxis = cartesian.getOtherAxis(baseAxis);

var barMinHeight = seriesModel.get('barMinHeight') || 0;

lastStackCoords[stackId] = lastStackCoords[stackId] || [];
lastStackCoordsOrigin[stackId] = lastStackCoordsOrigin[stackId] || []; // Fix #4243

Expand All @@ -290,7 +289,7 @@ export function layout(seriesType, ecModel) {
var isValueAxisH = valueAxis.isHorizontal();

var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked);

var valueAxisBase = getValueAxisBase(valueAxis)
for (var idx = 0, len = data.count(); idx < len; idx++) {
var value = data.get(valueDim, idx);
var baseValue = data.get(baseDim, idx);
Expand All @@ -302,7 +301,7 @@ export function layout(seriesType, ecModel) {

var sign = value >= 0 ? 'p' : 'n';
var baseCoord = valueAxisStart;

var isStackFull = lastStackCoords[stackId].length === len
// Because of the barMinHeight, we can not use the value in
// stackResultDimension directly.
if (stacked) {
Expand All @@ -326,7 +325,7 @@ export function layout(seriesType, ecModel) {
var coord = cartesian.dataToPoint([value, baseValue]);
x = baseCoord;
y = coord[1] + columnOffset;
width = coord[0] - valueAxisStart;
width = isStackFull ? coord[0] - valueAxisBase : coord[0] - valueAxisStart
height = columnWidth;

if (Math.abs(width) < barMinHeight) {
Expand All @@ -339,7 +338,7 @@ export function layout(seriesType, ecModel) {
x = coord[0] + columnOffset;
y = baseCoord;
width = columnWidth;
height = coord[1] - valueAxisStart;
height = isStackFull ?coord[1] - valueAxisBase : coord[1] - valueAxisStart;

if (Math.abs(height) < barMinHeight) {
// Include zero to has a positive bar
Expand Down Expand Up @@ -443,3 +442,8 @@ function getValueAxisStart(baseAxis, valueAxis, stacked) {

return valueStart;
}

function getValueAxisBase(valueAxis){
var valueBase = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
return valueBase;
}
164 changes: 164 additions & 0 deletions test/bar-stack-min.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<html>
<head>
<meta charset="utf-8">
<script src="lib/esl.js"></script>
<script src="lib/config.js"></script>
</head>
<body>
<style>
html, body, #main {
width: 100%;
height: 100%;
margin: 0;
}
#main {

background: #fff;
}
</style>
<div id="main"></div>
<script>

require([
'echarts',
'theme/dark'
], function (echarts, theme) {

var chart = echarts.init(document.getElementById('main'), 'dark');
var itemStyle = {
normal: {
label: {
show: true,
position: 'outside'
}
},
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowColor: 'rgba(0,0,0,0.5)'
}
};

console.profile('setOption');
chart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
legend: {
data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value',
min: 300
},
yAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
// xAxis: {
// type: 'category',
// data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']

// },
// yAxis: {
// type: 'value',
// min: 300
// },
series: [{
name: '直接访问',
type: 'bar',
stack: '总量',
label: {
normal: {
show: true,
position: 'insideRight'
}
},
data: [310,320,330,340,350,360,370]
},
{
name: '邮件营销',
type: 'bar',
stack: '总量',
label: {
normal: {
show: true,
position: 'insideRight'
}
},
data: [10,10,10,10,10,10,10]
},
{
name: '联盟广告',
type: 'bar',
stack: '总量',
label: {
normal: {
show: true,
position: 'insideRight'
}
},
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '视频广告',
type: 'bar',
stack: '总量',
label: {
normal: {
show: true,
position: 'insideRight'
}
},
data: [150, 212, 201, 154, 190, 330, 410]
},
{
name: '搜索引擎',
type: 'bar',
stack: '总量',
label: {
normal: {
show: true,
position: 'insideRight'
}
},
data: [820, 832, 901, 934, 1290, 1330, 1320]
}
]
});
console.profileEnd('setOption');
})

</script>
</body>
</html>