# Use list in Chart-function

**URL:** <https://community.wolfram.com/t/use-list-in-chart-function/4023>\
**Category:** Questions\
**Tags:** mathematica, graphics-and-visualization\
**Created:** [November 16, 2014, 6:48pm UTC](https://community.wolfram.com/t/use-list-in-chart-function/4023 "2014-11-16T18:48:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimbr](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jimbr](https://community.wolfram.com/u/jimbr)\
**Post date:** [November 16, 2014, 6:48pm UTC](https://community.wolfram.com/t/use-list-in-chart-function/4023/1 "2014-11-16T18:48:40Z")

</div>

How can I simplify this:

```
BarChart[{pPoäng[2], pPoäng[3], pPoäng[4], pPoäng[5], pPoäng[6], 
  pPoäng[7], pPoäng[8], pPoäng[9], pPoäng[10], pPoäng[11], pPoäng[12],
   pPoäng[13], pPoäng[14], pPoäng[15], pPoäng[16], pPoäng[17], 
  pPoäng[18], pPoäng[19], pPoäng[20], pPoäng[21], pPoäng[22], 
  pPoäng[23], pPoäng[24], pPoäng[25], pPoäng[26], pPoäng[27], 
  pPoäng[28], pPoäng[29], pPoäng[30], pPoäng[31], pPoäng[32], 
  pPoäng[33], pPoäng[34], pPoäng[35], pPoäng[36]}, 
 ChartLabels -> {Range[2, 36]}, AxesLabel -> {X}, ImageSize -> Large]

```

To something like this:

```
BarChart[{pPoäng}, ChartLabels -> {Range[2, 36]}, AxesLabel -> {X}, ImageSize -> Large]

```

I’ve tried multiple approaches and I either get an empty chart or the error message: “pPoäng is not a valid dataset or list of datasets”

TIA!

---

<div class="post-metadata">

**Author:** ![dreiss](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/dreiss/32/29094_2.png) [@dreiss](https://community.wolfram.com/u/dreiss)\
**Post date:** [November 16, 2014, 10:10pm UTC](https://community.wolfram.com/t/use-list-in-chart-function/4023/2 "2014-11-16T22:10:05Z")

</div>

What is pPoäng?

---

<div class="post-metadata">

**Author:** ![jimbr](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jimbr](https://community.wolfram.com/u/jimbr)\
**Post date:** [November 17, 2014, 9:05am UTC](https://community.wolfram.com/t/use-list-in-chart-function/4023/3 "2014-11-17T09:05:35Z")

</div>

Sorry, it should be a list with probabilities (floats).

```
omega = Sort /@ 
   Tuples[{Range[1, 4], Range[1, 6], Range[1, 8], Range[1, 12], 
     Range[1, 20]}];
ntot = Length[omega];
poäng[{x_, x_, x_, y_, y_} /; x != y] := 3 x + 2 y == p (* There are multiple lines like this *))
Do[pPoäng[p] = N[Count[omega, _?(poäng)]/ntot], {p, 2, 36}];

```

---

<div class="post-metadata">

**Author:** ![gerlij](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gerlij/32/32652_2.png) [@gerlij](https://community.wolfram.com/u/gerlij)\
**Post date:** [November 18, 2014, 4:11pm UTC](https://community.wolfram.com/t/use-list-in-chart-function/4023/4 "2014-11-18T16:11:20Z")

</div>

You can try mapping `pPoäng`:

```
BarChart[pPoäng /@ Range[2, 26], ChartLabels -> Range[2, 36], AxesLabel -> {X}, ImageSize -> Large]

```

I wouldn’t suggest this, though. If you look at the Information of pPöang, you’ll see that it is a function with values it will look up for each number 2..36.

```
?pPoäng

```

It would make more sense to use a list which will make it easier to use with BarChart as well but it will require some modifications to your code:

```
poäng[p_][{x_, x_, x_, y_, y_} /; x != y] := 3 x + 2 y == p;
pPoäng = N[Count[omega, _?(poäng[#])]/ntot] & /@ Range[2, 36];
BarChart[pPoäng, ChartLabels -> Range[2, 36], AxesLabel -> {X}, ImageSize -> Large]

```

Alternatively, if you have Mathematica 10, you can use `pPoäng` as an Association. This just requires you to put this line before the Do:

```
pPoäng = <||>;

```

Although I would suggest rewriting `poäng` the same way as above and the Do line as

```
(pPoäng[#] = N[Count[omega, _?(poäng[#])]/ntot]) & /@ Range[2, 36];

```

This is to keep `p` as a local variable.

And then you can draw the chart with

```
BarChart[pPoäng, ChartLabels -> Range[2, 36], AxesLabel -> {X}, ImageSize -> Large]

```
