Why do you simulate? Most likely, you want to obtain answers about life, the universe and everything. And what does your simulation produce? Numbers. And lots of them. In order to make sense of more than three numbers at once, we have invented the great art of charts. In this post, let’s explore how AnyLogic has taken on that art and how we can go beyond its limited capabilities…

Everybody loves (pie) charts...

Everybody loves (pie) charts...

So what is wrong with the current charts?

AnyLogic is great. I haven’t met anyone who seriously tried the software and said “aww, its rubbish”. However, there is one area that has always been a bit of an ugly step child: nobody talks about it, nobody plays with it much and when the topic comes up, people try to leave: AnyLogic charts.

They can be useful at times, but in my experience, they are too limited to “proper” use for these reasons:

  • There is only a limited number of chart types (the most important ones, granted)
  • Editing them is worth a PhD in its own right. Anyone who has tried to resize labels and chart areas will agree
  • There is no good labelling. Essentially, you are left to your own devices using the “Text” object on top of charts
  • The look is ok but most clients are used to Excel charts. It’s a subtle point but I feel people have less trust in charts looking different to what they are used to.

So what can you do to change it?

If you have played a little with AnyLogic, you might have noticed that this is not a simple drag’n’drop simulation tool. You can put in code everywhere and it’s all a bit confusing at the start, right? If you are an experienced user, you know that every object in AnyLogic is programmable. So in order to draw your dream chart, use existing objects from the “Presentation” palette and program to change their appearance during runtime.

Let’s say you want to plot a metric like the number of people passing through a door in real time. What you’d do is to change the height of a rectangle object depending on the number of people passing per minute.

This approach is very flexible as you can also change width, colour or object size. And you are not limited to rectangles. You can do the same with circles, lines or texts. You are not even limited to the “Presentation” library. Feel free to change the appearance of buttons, pictures or space markup. This is actually done in several AnyLogic example models. It’s not a hack, it’s a design feature :-)

Let’s spell this out more practically:

Do it yourself...

Grab your latest model and grab a metric you want to plot. Let it be some number that changes over time. In my sample model, I will vary the variable “myMetric” randomly over time as below:

The event "changeMyMetric" changes the variable "myMetric" randomly.

The event "changeMyMetric" changes the variable "myMetric" randomly.

Now drag in the “Rectangle” object from the “Presentation” library. Explore its properties: you can make the “Height” dynamic and allow it to change during runtime (by clicking the little “=” sign next to it). In the text box, enter your metric like I did below:

Make the green rectangle change its height when "myMetric" changes.

Make the green rectangle change its height when "myMetric" changes.

Run your model and observe how the rectangle changes its height as your metric changes. You might need to adjust it by a factor to scale it nicely.

Now keep playing. Say you want to plot a number of values from a collection of data: you can replicate your rectangle and change its “X” position by its index. This way, you can plot neat bar charts very easily. Check this chart from one of my recent models: it actually plots several bars on top of each other and you can view/hide parts of the chart:

An interactive bar chart for each simulation week. This uses buttons as well.

An interactive bar chart for each simulation week. This uses buttons as well.

With this chart, you can overlay transparent information...

With this chart, you can overlay transparent information...

... or turn it off.

... or turn it off.

The holy grail

So far, we have only touched basics. The logical next step would be to combine your model animation (you do have one, right?) with charts. There are some elegant AnyLogic example models doing this already. Launch the “Oil supply chain” model and let it run a little. You will notice that the refinery animation change over time like a pie chart:

The black'n'wite dots are our refineries...

The black'n'wite dots are our refineries...

Lets explore how this feat is achieved: In the “Refinery” class, there is a black arc object representing the refinery. In its properties, you will notice the same magic applied as you did above:

The pie chart changes with model metrics...

The pie chart changes with model metrics...

First, the black arc is on top of a white circle, leaving the impression of a pie chart. The radius changes with capacity so that the arc (and circle) actually grows when capacity is increased. Note the “log” function that avoids a linear increase in size. The “Angle” property changes how much of the pie becomes black as the ratio of stockOut over capacity. Again, model metrics are used to change how the pie changes.

The neat thing is to combine this chart into the model animation. Thereby, your client can feel at home without the need to mentally analyse separate charts. It is both convenient and elegant.

Verdict

AnyLogic charts are useful in specific circumstances. However, you can expand the power of model analysis greatly by creating your own charts. There are infinite possibilities to be creative and create useful charts. The key to success is to apply dynamic object properties to get objects to change when model metrics change.

How do you improve charts and display your model results creatively? Share your thoughts, curious to find the most intriguing AnyLogic chart to date :-)

2 Comments

English
German