How do you use the chart2D plugin to create a chart with time as the horizontal axis

I want to use chart2D plugin to draw a chart with a horizontal axis current time (month: day: hour: month:second) and a vertical axis representing real-time data. But no solution is found. Sincerely thank you for your answers!

The component or an extension? If you're using an extension, please provide a link to the topic where you found it?

realtime_chart.aia (3.0 KB)

here is an example.
It will update every 1 second.

4 Likes

(added to FAQ)

Hi,
How can I stop this chart from shifting to the left? This chart is impressively simple and powerful, (like AI2 of course), but I'm too old, too blind to... (as in the already famous Al Pacino says in Devil's Advocate) to learn AI2. So I ask for help.

I played an entire night with its cart, I managed to change the speed to max allowed speed, on my tablet - it seems I can use this cart for my project. Also, I managed to connect two sliders, one for frequency, and one for the length of data to be plotted. I started to make two lists with the intent to plot a packet of data in parallel (to stop it from shifting, now I think that it is possible not to be the way for stop shifting purposes.)

Can @Kevinkun or another AI2 specialist stop this chart from shifting to the left?

Thank you in advance, Dan

then you just want to add more data entry at right? that will show more and more entries and make the chart not readable.

Hi, @Kevinkun I want to show let's say... 100 y data on a 100 x (time) axis, after that I want to erase that data and display another set. Somehow dynamic data in frames. Practically something like an oscilloscope or more precisely something like a logic analyzer.

Thank you in advance, Dan

After adding an entry to the graph, check if its item count exceeds 100. If so, empty it out.

Hi, @ABG thank you for for taking the time to look at my problem. My logic fails somewhere... I tried all this and more last entire night.

The "call ChartData2D1.clear" made sense to me from the first moment and I asked myself why @Kevinkun does not use it as an alternative to clear the chart?! Well... I try to use it in various implementations with the same error. Seems that AI2 doesn't like that implementation and I don't know why. The logical ideas end for me. After that, I try to make two lists with 10 values one for x and one for y, and use that lists to AddEntry and RemoveEntry. I make the list for y but when I try to make the list for x, I don't know how to make it counting x values like 1,2,3,4... and so on. That thing for somebody who knows AI2 is a child game, for me, it's rocket science.

Anyway... I'm very curious, after that in the end I have this chart functional as I want, which is the max speed of the chart refresh rate.

Thank you for your time, best regards, Dan

EDITED - The error appears after the first 10 values are printed correctly.

48b2e2571969aa219e9219f04c0c5e750e0c89f2_2_690x408
This caused your error message.


blocks (1)
blocks (2)

charts_drunkard_walk.aia (2.2 KB)
sample run

@ABG Thank you very much for your method that it's working. "After adding an entry to the graph, check if its item count exceeds 100. If so, empty it out.". You say that. The simplest way for my logical point of view was:

This doesn't work. If you spend some minutes more to explain for me (and for others) why in the next image...

math

Why I can use the first expression to sum 1 but I can't use the second to give a value "0" both are math expressions?!

That explication can be "didactical" not only for me...

Why do you make a variable for y?!
And the logic with "length of the list" - came from experience!!! It is very useful.

Thank you for your time, best regards, Dan

@ABG If you give a try at this:

You will see an interesting thing... The speed of plotting on the graph is lower and lower... step by step until it freezes at least on my tablet. I think that this gives that behavior:

speed_problems_1

In the original @Kevinkun approach:

That problem doesn't appear (at least on my tablet).

On my tablet, with Kevinkun approach, I obtain a plotting time for a point under 15 us - that can be interesting to give a try in 100 points chart plotting, but this will be another story.

Thank you for your time, best regards Dan.

In AI2, the '=' is the math comparison operator, which returns true or false.
In other languages like FORTRAN and C and Java, '=' is used for assignment, and == is used for comparison.

In AI2 your second block was trying to assign into variable x the result of comparing x with 0, (true or false). Once x got the value true or false, it poisons further attempts at adding +1 to it, since true and false are not numbers.

Without an .aia to test, I am guessing that your 1 ms Clock Timer interval is too fast for the AI2 Companion and Charts component.

There is also the issue of garbage collection, which happens periodically to clean up leftover memory allocations in list based structures behind the scenes. Different components are more efficient than others at this.

I like the drunkards walk for dynamic chart examples. It doesn't jitter as much as a pure random y value. But it requires accumulation of the steps, like a drunkard's distance from his starting position, and that requires an extra variable (y).

I just used your example in a initial test where I display the tilt Y of a micro controller. It is working but my app crashes after a number of seconds so more work to do. :slightly_smiling_face:

any error message? or post relevant blocks?
maybe others can help, or i will check tomorrow, since it's very late here.

1 Like

I don't get any messages, it just crashes. In companion and when build. It also crashes even when I am not connecting to the micro controller. I will go back to your aia and see if I can let it crash.

Edit: No, your aia doesn't crash.

Here is the aia
FlyingBirdChart.aia (487.5 KB)
You just have to open it in the companion and run it by pressing the button. My lines are going to the right, yours not. I have the same blocks, I only changed chart range and the random numbers. I don't see what is happening.

If you could take a look that would be great.

the problem is:
global x is set to 1 in my example, but you set it as 0 in yours.

to better understand, you can change the Clock.Timer() to :slight_smile: