stacked bar graph

All topics specific to modeling questions in Enterprise Dynamics
Post Reply
Yfke
Posts: 14
Joined: Friday 13 April, 2018 - 10:54

stacked bar graph

Post by Yfke »

Hello there,

I would like to create a stacked bar graph with two series. I can create two series, but the graph
shows them next to eachother. I can fix this by hand, every time after running the simulation. But, there
must be a way to do this automatically. Does anyone know how?

Thanks in advance,

Kind regards,
Yvonne
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: stacked bar graph

Post by HarryBunnik »

Ha Yvonne,

Yes, it is possible on code... But it will take a bit of tweaking since it is unfortunately not a standard option of the Graph atom.

I've made some adjustments to the example model (TableAndgraph.mod) so you can see what I'm pointing on.

TableAndGraph_Stacked HB.mod
(20.74 KiB) Downloaded 162 times
  • First you have to open your model tree and select the graph-atom (in my case the 6th atom in the model. You can select the atom in the 2D animation window and press Ctrl+T to find it quickly).
  • Then you press the F9 button (this will allow you to edit some of the properties of the atom).
  • Select the Event tab (here you'll see all the Events/Code that define the atom and handle all that it's doing).

    At the moment all is empty (only a small "0" is seen in the column before the fileds normally containing the code. This is because this is a child atom and all the code is stored on the mother, which is standing in the library).
    Normally you don't want to change the code of a child since that means that when updates are done to the atoms, the overwritten code will keep standing and the update is ignored. However, in this case, we only want to do a small change on one graph, and not for all).
  • Then go to the OnUser event (that is where the code is standing that is handling what happens when the user is clicking on the atom, so opening a GUI or showing, in this case, a graph).
  • Double click in the field of the user and it will ask if you want to inherit the code (copy it from the mother).
  • Click yes.
  • Now the field is filled with code and here we have to add that the series must be stacked. This can be done by adding the line "GraphSeriesProperty(1, [MultiBar], [mbStacked])" just after the graph is being displayed. So we have to change:

    Code: Select all

    DisplayGraph(AtomID(c))


    to:

    Code: Select all

       Do(
         DisplayGraph(AtomID(c)), 
         GraphSeriesProperty(1, [MultiBar], [mbStacked])
       )
  • Then you have to press the Apply button and save your model.
  • If you now open the Graph in your model, you'll see that the second serie is stacked. If you ahve a third series, you'll have to add an extra line. Note that the counting of the series start at 0 and not at 1.
  • If you want to see what the other options are, you can have a look in the Help by placing the cursor in the word "GraphSeriesProperty" and press F1.
I hope this helps you.

Cheers,

Harry
Yfke
Posts: 14
Joined: Friday 13 April, 2018 - 10:54

Re: stacked bar graph

Post by Yfke »

Hi Harry!

Thank you, it works fine now! :D

Kind Regards,
Yvonne
Yfke
Posts: 14
Joined: Friday 13 April, 2018 - 10:54

Re: stacked bar graph

Post by Yfke »

Do you maybe also know how to change bar colors?
I tried BarBrush, but it doesn't work.

In my model, each bar represent a product. I would like to give the product (bars) alternately different colors.
Do you know if/how this is possible?

Kind regards,
Yvonne
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: stacked bar graph

Post by HarryBunnik »

Ha Yvonne,

You can try to use: GraphSeriesProperty(2, [SeriesColor], ColorRed) in the same way as before.

I'm only starting to doubt if the index of the series is really starting at 0 or at 1. When I use the 2, the second series is taken. So it can be that I was wrong there. You'll have to play a bit with it.

When you type in Color###, the autocomplete will show you a range of already predefined colours. Otherwise, you can use the function "RGBcolor(#,#,#)"

Cheers,

Harry
Yfke
Posts: 14
Joined: Friday 13 April, 2018 - 10:54

Re: stacked bar graph

Post by Yfke »

Yes that is true, thanks!
Post Reply