MBS chart director stupid questions

Hi. Just when you thought you got away with a 1 week period of no stupid questions:

I am using MBS chart director to graph data.
I sort-of get it, and sort of dont’t

I have a chart, myChart as a property on
window 4…

then I have a function I call that :

I add the Y data…
call window4.mychart.addLineLayer.addDataSet(data0)

I add the X data
call window4.mychart.xAxis.setLabels(x_axis)

I create a picture of the chart from the data
(which is what MBS is supposed to do right?)

p=window4.mychart.makeChartPicture

I then put that picture into a picture

window4.pic =p

and then I get my picture and I am happy… Almost…
The issue arises when I call the function a second time,
with new data, the new data is not used, and the original
picture is not updated. Do I need to “clear out” the data
that I had sent to charDirector before I can call it again?

It seems like maybe you “get” one shot at calling makeChartPicture ?
and if you call it again, regardless of new data, it will
not generate a new picture??

Any help would be appreciated.

Your function to make the chart could create the chart object again, set properties and data to get a new chart.

How do I do this?
Right now, I call the constructor and destructor in a function
replot_energy() – and that works ok…
but the issue is that this is code taken from the example where
you hover the mouse over the chart and it tells you the
value at the mouse location. If the object is destroyed after use,
the trackLineLegend() sub throws an exception.

When something changes, create new chart objects and throw away the old one.

For trackLineLegend you keep it in a property, but when you change input data, you create a new one.

I am a beginner. I don’t really understand.

I also have a problem where on windows, the chars look OK, but
when cross compiled to the RPI none of the numbers show up…

here are the pictures of RPI(bad) Windoes (good)
http://www.mediafire.com/folder/0i4u7qsf2m1y1/graph_fail

This is my code… (yes it is a very ugly mashup of examples
that came from MBS – but in my defense, I am still a beginner!)

dim x as integer

dim data0(575) as double
dim data1(575) as double
dim x_axis(575) as double

dim p as Picture

utilities.graph_test = utilities.graph_test +1
for x = 1 to 576
data0(x-1)=utilities.wheel_amplitude(x) '+rnd()1000utilities.graph_test
data1(x-1)=0
x_axis(x-1)=x
next x

window4.mychart.Destructor ’ have to destroy object so we don’t run out of memory

window4.mychart.Constructor ’ have to make a new one, because you cant call makeChartPicture more than one time ???

call window4.mychart.addTitle(“Enegy per timeslot”, “timesbi.ttf”, 18)

call window4. mychart.setPlotArea(50, 55, window4.mychart.getWidth - 100, window4.mychart.getHeight - 90, window4.mychart.linearGradientColor(0, 55, 0, window4.mychart.getHeight - 35, &hf0f6ff, &ha0c0ff), -1, CDBaseChartMBS.kTransparent, &hffffff, &hffffff)

call window4.mychart.addLegend(50, 25, false, “arialbd.ttf”, 10)

// Set axis label style to 8pts Arial Bold
call window4.mychart.xAxis.setLabelStyle(“arialbd.ttf”, 8)
call window4.mychart.yAxis.setLabelStyle(“arialbd.ttf”, 8)
call window4.mychart.yAxis2.setLabelStyle(“arialbd.ttf”, 8)

// Set the axis stem to transparent
window4.mychart.xAxis.setColors(CDBaseChartMBS.kTransparent)
call window4.mychart.yAxis.setColors(CDBaseChartMBS.kTransparent)
call window4.mychart.yAxis2.setColors(CDBaseChartMBS.kTransparent)

// Configure x-axis label format
'c.xAxis.setMultiFormat(CDBaseChartMBS.StartOfYearFilter, "{value|mm/yyyy} ", CDBaseChartMBS.StartOfMonthFilter, “{value|mm}”)

// Add axis title using 10pts Arial Bold Italic font
call window4.mychart.yAxis.setTitle(“Amplitude”, “arialbi.ttf”, 10)
'call mychart.yAxis2.setTitle(“Effective Load (kg)”, “arialbi.ttf”, 10)

// Add a line layer to the chart using a line width of 2 pixels.
dim layer as CDLineLayerMBS = window4.mychart.addLineLayer
layer.setLineWidth(2)

call window4.mychart.setPlotArea(50, 55,window4.canvas1.Width- 100, window4.canvas1.height- 90, window4.mychart.linearGradientColor(0, 55, 0, window4.mychart.getHeight - 35, &hf0f6ff, &ha0c0ff), -1, CDBaseChartMBS.kTransparent, &hffffff, &hffffff)

'add x axis data
call window4.mychart.xAxis.setLabels(x_axis)

’ add y axis daya
call window4.mychart.addLineLayer.addDataSet(data0,&hcc0000, “Energy”)

// scaling of y axis
window4.mychart.yAxis.setLinearScale 0, 250000

// Display 1 out of 3 labels on the x-axis.

window4.mychart.xAxis.setLabelStep(50)

// Output the chart

p=window4.mychart.makeChartPicture ’ apparently you only get one of these per dat set??

if (p<>nil) then
window4.pic =p
end if

// fix some properties if set wrong in IDE

window4.canvas1.DoubleBuffer = false
window4.canvas1.EraseBackground = false

#if RBVersion >= 2013.0 then
window4.canvas1.Transparent = False
#endif

There are probably a few problems. Like calling window4.mychart a ton of times is not a good idea.

Please put the code into the window, so you don’t have to use the window name there to access properties.

For Linux, please add call to SetFontSearchPath to show where the fonts are.
see
https://www.monkeybreadsoftware.net/faq-howtogetfontstoloadinchartsonlinux.shtml

If you review an example like “Track Line with Legend” project, you can see the code in open event there.

c = new CDXYChartMBS(640, 400)

we create a new chart there.
So you would put that code from open event into a method, e.g. “update”. From the “Dim r” line on top to the “me.invalidate” line on bottom. In open event you add the “update” call to create chart. Now you could add a button to call this update method and see the chart changing.

I could email you the new project. Maybe you like to email me? Or use the trial license form.

the CDRanSeriesMBS must have a random seed, so e.g. like this:

Dim r As New CDRanSeriesMBS(200*rnd)

OK I put this code in app.open
’ register (my keys not posted here in help forum!!!

if not registerMBSPlugin(n, p, e, s+t) then
MsgBox “MBS Plugin serial not valid?”
end if

if (TargetLinux or TargetARM)then
CDBaseChartMBS.SetFontSearchPath “/usr/share/fonts/truetype”
msgbox “did it 2”
end if

I get the message box indicating that it set the path,
but it still doesn’t work. Do I need to put the code somewhere else?
here is a listing of that directory:

pi@raspberrypi:~/test2 $ ls /usr/share/fonts/truetype/ -l
total 32
drwxr-xr-x 2 root root 4096 Apr 18 2018 dejavu
drwxr-xr-x 2 root root 4096 Apr 18 2018 droid
drwxr-xr-x 2 root root 4096 Apr 18 2018 freefont
drwxr-xr-x 2 root root 4096 Apr 18 2018 lato
drwxr-xr-x 2 root root 4096 Apr 18 2018 liberation2
drwxr-xr-x 2 root root 4096 Apr 18 2018 noto
drwxr-xr-x 2 root root 4096 Apr 18 2018 openoffice
drwxr-xr-x 2 root root 4096 Apr 18 2018 piboto
pi@raspberrypi:~/test2 $

Well, what fonts do you use?
Are they in that folder?