ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Chart in VBA
Posted by Ciwa on Jan-01-2020 21:07
Hello,

This is the first time i'm using ChartDirector.

I try the example in VB6 is work fine, but when i try in the FactoryTalk from Rockwell Software which have VBA, i've got error message at line :

Set viewer.Picture = c.makePicture()

the error is VBA code has been halted. Reason: Run-time error - Methos 'Picture' of object '_ChartViewer' failed.

Please advise

  Re: Chart in VBA
Posted by Peter Kwan on Jan-02-2020 14:43
Attachments:
Hi Ciwa,

I happened to have a customer who is using ChartDirector or ASP/COM/VB with FactoryTalk to plot charts.

He had the same issue you mentioned. So we tried using another control to display the chart. (ChartDirector charts are standard images and can be displayed by many controls.)

We tried to use the Image control in the "Microsoft Forms 2.0 Object Library" to display the chart instead. (FactoryTalk View Site Guide about the "Microsoft Forms 2.0 ActiveX Controls" in page 404.) Our customer mentioned it can display a static image but not a dynamic image. It cannot even load an image file on the hard disk dynamically (using something like "Image1.Picture = LoadPicture(filename)").

Eventually, we successfully display the chart image by using the "Microsoft Web Browser" ActiveX control (see attached image). The code that does this is:

' Generate a temporary filename
fName = Environ("temp") & "test.bmp"
' Save the chart as an image using the filename
Call c.makeChart(fName)
' Display the image in the control
Call WebBrowser1.Navigate("about:<html><body scroll='no' style='border:1px solid #888'><img src='" & fName & "'></body></html>")

Note that the above workaround only displays the chart. It does not have user interaction features such as track cursors, zoom/scroll, etc..

As I do not have FactoryTalk, my test code are written in Excel VBA. I have attached my test Excel file for your reference. You can try to open the Excel file, make sure you "Enable Macros", and press the "Random Bars" button to generate a random bar chart.

Regards
Peter Kwan
browser_control.png
cd_excel_demo_web_browser_ctrl.zip
cd_excel_demo_web_browser_ctrl.zip

21.66 Kb

  Re: Chart in VBA
Posted by Ciwa on Jan-06-2020 16:03
Thank Peter, its work with web browser.

Another question,
I have created spline chart with 3 point and its work well. Is there a method to get y value given x value in created chart?

  Re: Chart in VBA
Posted by Peter Kwan on Jan-08-2020 03:00
Hi Ciwa,

Unluckily, for a spline curve, there is no API to obtain the y value given the x value.

Internally, ChartDirector does not keep track of every pixel that it draws. For a spline curve, after it draws a pixel, ChartDirector will forget about it and draws the next pixel. So after drawing the line, ChartDirector does not keep a lookup table that maps x values to y values. There is also no explicit formula to compute the y-value given the x-value. (The spline is not defined as y = f(x). It is a parametric spline defined as x = f(t), y = g(t).)

Regards
Peter Kwan