# How to make Excel-like data bars?

I would like to make a grid where each cell background is partially filled according to the numerical value being represented (on a scale from 0 to 1). Similar functionality to the one requested in this TeX.SE question.

How can I achieve this with Mathematica?

• It always helps if you give some example data and list some Mathematica code that you gave tried.
– Jens
Jul 15, 2013 at 23:55

You can also use the HorizontalGauge function introduced in version 9. For example:

bar = HorizontalGauge[#, {0, 100}, GaugeMarkers -> "ScaleRange",
GaugeStyle -> {Darker@Green, GrayLevel[0.95]}, TicksStyle -> None,
GaugeFrameSize -> None, ScalePadding -> 0, ImageSize -> 200, AspectRatio -> 1/5,
LabelStyle -> None, Epilog -> Text[Style[#, FontSize -> 15], Scaled[{0.8, 0.5}]]] &;

Grid[Map[bar, RandomInteger[{10, 90}, {4, 4}], {2}], Frame -> All]


• I'm embarrassed to be getting so many upvotes for my stolen version of your answer... :) Jul 16, 2013 at 21:21

I liked rm-rf's gauged solution so much that I made an interactive version:

bar[n_] := DynamicModule[{x = n},
HorizontalGauge[Dynamic[x], {0, 100}, GaugeMarkers -> "ScaleRange",
GaugeStyle -> {Darker@Green, GrayLevel[0.95]}, TicksStyle -> None,
GaugeFrameSize -> None, ScalePadding -> 0, ImageSize -> 200,
AspectRatio -> 1/5, LabelStyle -> None,
Epilog ->
Text[Style[Dynamic[x], FontSize -> 15], Scaled[{0.8, 0.5}]]]]
Grid[Table[bar[RandomInteger[{10, 90}]], {4}, {4}], Frame -> All]


Ideal for those last minute adjustments to that troublesome dataset...

• "Ideal for those last minute adjustments to that troublesome dataset..." or to show on conference that global warming is a fact. :p
– Kuba
Jul 16, 2013 at 7:38
• @kuba :) I'd laugh if I thought it never happened... Jul 16, 2013 at 7:49
– Kuba
Jul 16, 2013 at 8:05
• Very nice! Thanks
– dabd
Jul 16, 2013 at 17:06

Something like this?

Grid[Map[Graphics[{GrayLevel[0.8],
Rectangle[Scaled[{0, 0}], Scaled[{#, 1}]], Black,
Style[Text[#], Large]}, AspectRatio -> 0.2] &,
RandomReal[{0, 1}, {4, 3}], {2}], Frame -> All]


Of course you can place the Text and style to taste. Here is a slightly more complex version:

Grid[Map[Graphics[{GrayLevel[0.8],
Rectangle[Scaled[{0, 0}], Scaled[{#, 1}]], Black,
Inset[Text[
Style[NumberForm[#, {3, 3}], Large,
FontFamily -> "Franklin Gothic"]], Scaled[{0.8, 0.5}]]},
AspectRatio -> 0.2] &, RandomReal[{0, 1}, {4, 3}], {2}],
Frame -> All, FrameStyle -> Directive[GrayLevel[0.9]], Spacings -> 0]


It would be straightforward to create a function that took a matrix of numbers and generated this.