Skip to content

Commit

Permalink
fix: fix stacked bar not drawn because of NaN value brought in #11951
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Feb 27, 2020
1 parent ca4c391 commit 9adb6a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/chart/bar/BarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export default echarts.extendChartView({
bgEls[dataIndex] = bgEl;
}

// If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
if (!data.hasValue(dataIndex)) {
return;
}
Expand Down
10 changes: 8 additions & 2 deletions src/layout/barGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ export function layout(seriesType, ecModel) {
if (Math.abs(width) < barMinHeight) {
width = (width < 0 ? -1 : 1) * barMinHeight;
}
stacked && (lastStackCoords[stackId][baseValue][sign] += width);
// Ignore stack from NaN value
if (!isNaN(width)) {
stacked && (lastStackCoords[stackId][baseValue][sign] += width);
}
}
else {
var coord = cartesian.dataToPoint([baseValue, value]);
Expand All @@ -465,7 +468,10 @@ export function layout(seriesType, ecModel) {
// Include zero to has a positive bar
height = (height <= 0 ? -1 : 1) * barMinHeight;
}
stacked && (lastStackCoords[stackId][baseValue][sign] += height);
// Ignore stack from NaN value
if (!isNaN(height)) {
stacked && (lastStackCoords[stackId][baseValue][sign] += height);
}
}

data.setItemLayout(idx, {
Expand Down
2 changes: 1 addition & 1 deletion test/bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

for (var i = 0; i < 10; i++) {
xAxisData.push('类目' + i);
data1.push((Math.random() * 5).toFixed(2));
data1.push(i === 0 ? '-' : (Math.random() * 5).toFixed(2));
data2.push(-Math.random().toFixed(2));
data3.push((Math.random() + 0.5).toFixed(2));
data4.push((Math.random() + 0.3).toFixed(2));
Expand Down

0 comments on commit 9adb6a9

Please sign in to comment.