8

Trying to make a waterfall bar chart. I got this far:

yData = {10, 7, 4, 2}
upFromX = Accumulate[yData] - yData
xyDataWithUplift = 
 Table[{Style[upFromX[[i]], White], yData[[i]]}, {i, 1, Length[yData]}]
BarChart[xyDataWithUplift, ChartLayout -> "Stacked"]

which is getting there but I can't figure out how to make the bottom rectangle's edge blank. Tried EdgeForm[] and EdgeForm[White] but no luck.

kglr
  • 394,356
  • 18
  • 477
  • 896
Joe
  • 1,467
  • 7
  • 13

3 Answers3

14

How about this?

yData = {10, 7, 4, 2, -5, -2, 3};
    BarChart[yData, ChartLayout -> "Stepped"]

enter image description here

OkkesDulgerci
  • 10,716
  • 1
  • 19
  • 38
  • thx - that's so obvious it never occurred to me... now that I see it, that's exactly how a 'stepped' layout should behave1 – Joe May 06 '18 at 04:26
1
yData = {10, 7, 4, 10, -5, -2, 4};

To visualize step directions, we can use ChartLayout -> "Stepped" with built-in ChartElementFunctions as follows:

"FadingRectangle"

BarChart[yData, 
 ChartLayout -> "Stepped", 
 ChartStyle -> Red, 
 ImageSize -> Large, 
 ChartElementFunction -> 
  ChartElementData["FadingRectangle", "GradientOrigin" -> Bottom]]

enter image description here

"GradientRectangle"`

BarChart[yData, 
 ChartLayout -> "Stepped", 
 ImageSize -> Large, 
 ChartElementFunction ->  ChartElementData["GradientRectangle", 
   "ColorScheme" -> {Red, Orange, White},
   "GradientOrigin" -> Bottom]]

enter image description here

"ArrowRectangle"

BarChart[yData, 
 ChartLayout -> "Stepped", 
 ImageSize -> Large, 
 ChartElementFunction -> "ArrowRectangle"]

enter image description here

Alternatively, use both ChartElementFunction and ColorFunction:

BarChart[yData, 
 ChartLayout -> "Stepped",
 ColorFunction -> "Rainbow", 
 ChartLegends -> Automatic, ImageSize -> Large, 
 ChartElementFunction -> 
  ChartElementData["ArrowRectangle", "ArrowWidth" -> .8, 
   "TaperRatio" -> 0, "ArrowheadAngle" -> 120]]

enter image description here

Note: We can access the options for a built-in ChartElementFunction using "Options" as the second argument:

ChartElementData["ArrowRectangle", "Options"]
{"TaperRatio" -> 0, "ArrowheadAngle" -> 60, "ArrowWidth" -> 0.6} 
kglr
  • 394,356
  • 18
  • 477
  • 896
0

I expected ChartStyle -> {{None, Automatic}} to work but it still had the edge.

ChartStyle -> {{Directive[EdgeForm[], FaceForm[]], Automatic}} on the other hand does remove the edge.

Brett Champion
  • 20,779
  • 2
  • 64
  • 121