6
$\begingroup$

Is there anyone who know how to make diagonal lines inside the chart bar like the below picture?

enter image description here

$\endgroup$
1
  • $\begingroup$ If any of the answers you got solved your problem, please consider accepting them by clicking the grey checkmark in their left. $\endgroup$
    – Szabolcs
    Mar 15, 2013 at 17:03

4 Answers 4

10
$\begingroup$

There has to be a better way than this:

BarChart[{1, 2, 3, 4, 5, 6}, 
 ChartElements -> 
  Graphics[{Blue, Thick, Line[{{0, 0}, {0.5, 0.05}}]}]]

enter image description here

$\endgroup$
4
  • $\begingroup$ It is great. Thanks a lot. $\endgroup$
    – Kim
    Mar 14, 2013 at 15:58
  • 2
    $\begingroup$ +1 But (@Kim) please read Tufte on Moire patterns and chartjunk. Kudos to WRI for making this kind of stuff hard to construct. $\endgroup$
    – whuber
    Mar 14, 2013 at 17:27
  • 1
    $\begingroup$ @whuber, yes you're right, I forgot myself. I feel guilty now... :) $\endgroup$
    – cormullion
    Mar 14, 2013 at 17:52
  • 3
    $\begingroup$ Your illustration is a beautiful example of what Tufte writes about: the space between bars really does seem to vibrate, even more so on the screen than on the printed page. Quite distracting and very useful if your objective is to draw attention away from the data. :-) $\endgroup$
    – whuber
    Mar 14, 2013 at 18:43
6
$\begingroup$

With apologies to @whuber and Tufte :)

You can also do the following using Texture and System`BarFunctionDump`TextureBar as ChartElementFunction.

First, using the function hatchF from this answer

ClearAll[hatchF]
hatchF[mf_List: {# &, #2 &}, mesh_List: {50, 50}, 
  style_: GrayLevel[.5], opts : OptionsPattern[]] := 
 ParametricPlot[{x, y}, {x, 0, 1}, {y, 0, 1}, Mesh -> mesh, 
  MeshFunctions -> mf, MeshStyle -> style, BoundaryStyle -> None, 
  opts, Frame -> False, PlotRangePadding -> 0, ImagePadding -> 0, Axes -> False]

to create hatched images

t1 = hatchF[{# - #2 &}, {20}, White, MeshShading -> {Blue, White}];
t2 = hatchF[{# - #2 &, #2 + # &}, {20}, Gray, PlotStyle -> None, 
   MeshShading -> {{Blue, White}, {Red, Yellow}}];

And a few Texture examples from ExampleData:

t3 = ExampleData[{"ColorTexture", "Metal4"}];
t4 = ExampleData[{"ColorTexture", "WhiteMarble"}];
t5 = ExampleData[{"ColorTexture", "Kingwood"}];

Then, Texture these images and use them as the setting for PlotStyle together with System`BarFunctionDump`TextureBar for the option ChartElementFunction:

BarChart[{3, 2, 3, 4, 3}, 
 ChartStyle -> (Texture /@ {t1, t2, t3, t4, t5}), 
 ChartElementFunction -> System`BarFunctionDump`TextureBar]

enter image description here

You can go further along this slope:

RectangleChart[Tuples[{1, 4, 3}, 2], 
 ChartStyle -> (Texture[ImageMultiply[ExampleData[{"TestImage", "Mandrill"}], #]] & /@ 
    ColorData[30, "ColorList"]), 
 ChartElementFunction -> System`BarFunctionDump`TextureBar]

enter image description here

$\endgroup$
2
$\begingroup$

Version 12.1 introduced HatchShading which can be used as part of a ChartStyle specification:

BarChart[{1, 2, 3, 4, 5, 6}, 
    ChartStyle -> Directive[Blue, HatchFilling[Pi/4, 2]]]

enter image description here

$\endgroup$
1
$\begingroup$

Since Version 12.1 there is also PatternFilling which offers countless possibilities.

BarChart[{1, 2, 3, 4, 5, 6},
 ChartStyle -> PatternFilling["Weave", ImageScaled[1/20]]]

enter image description here

BarChart[{1, 2, 3, 4, 5, 6},
 ChartStyle -> PatternFilling[{"Checkerboard", Red, Black}, ImageScaled[1/20]]]

enter image description here

$\endgroup$

Your Answer

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

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