8
$\begingroup$

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.

$\endgroup$

3 Answers 3

14
$\begingroup$

How about this?

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

enter image description here

$\endgroup$
1
  • $\begingroup$ thx - that's so obvious it never occurred to me... now that I see it, that's exactly how a 'stepped' layout should behave1 $\endgroup$
    – Joe
    May 6, 2018 at 4:26
1
$\begingroup$
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} 
$\endgroup$
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.