One way to do this is using Graph-Template files:
The Template file can originally be generated by using the save as command on the Default Graph Template in the XY function Navigator.
So at first visualize a Graph the way you like "by Hand" and afterwards generate your Template file.
You then get an xml file that can also easily be edited with a text editor.
To use this Template file in your automation, the following lines do the work for you:
Dim baseTemplateManager1 As CAE.Xyplot.BaseTemplateManager baseTemplateManager1 = theSession.XYPlotManager.GetTemplateManager2d() 'unload allTemplates: baseTemplateManager1.UnloadAllTemplates() 'load your Template file baseTemplateManager1.LoadTemplate("MyTemplatefile.
xml") 'activate your Template file baseTemplateManager1.ActiveTemplate = "MyTemplatefile.xml"
The code is in VB but it should give a hint what's to do in c#.
Thanks fo your support, but with the help of graph template I am not able to save the title of the graph. Can you please help me to solve this issue as well.
within an Automation there are several methods to create a Graph.
when you are using
theSession.Post.CreateHistoryGraph(.... 'Or theSession.Post.CreateSpatialGraph(....
you can set the Name of your Graph through one of the Parameters you need to pass into these functions.
Are you using these functions or something else?
Okay, so then maybe this can help you:
(I haven't tried this out but it looked promising)
Dim XValues() As Double = Nothing Dim YValues() As Double = AfuData.GetRealData(XValues) Dim arrayRecord2D1 As CAE.FTK.ArrayRecord2D arrayRecord2D1 = theSession.DataManager.CreateArrayRecord2d("Your Graph Title here", "Your Graph Legend here", XValues.Length)
'Putting your afu Data into an array Record because on this one you can set the Title, etc... arrayRecord2D1.SetXCoordinatePoints(XValues) arrayRecord2D1.SetYCoordinatePoints(YValues) 'Unit for the X-Axis (Time for example): Dim baseUnit1 As CAE.FTK.BaseUnit = theSession.DataManager.CreateArrayUnit(CAE.XyFunct
ionMeasure.Time, CAE.XyFunctionUnit.TimeSec) baseUnit1.SetMeasureName("Your X-Axis Title here") 'Unit for the Y-Axis (Pressure for example): Dim baseUnit2 As CAE.FTK.BaseUnit = theSession.DataManager.CreateArrayUnit(CAE.XyFunct ionMeasure.Pressure, CAE.XyFunctionUnit.PressurePa) baseUnit2.SetMeasureName("Your Y-Axis Title here")
'Passing the Created Units to the arrayRecord: arrayRecord2D1.SetXCoordinateUnit(baseUnit1) arrayRecord2D1.SetYCoordinateUnit(baseUnit2) 'Pushing Your array Record into an arrayRecord-Array ( :-) ) Dim records(0) As CAE.FTK.BaseRecord records(0) = DirectCast(arrayRecord2D1, CAE.FTK.BaseRecord) 'Create some PlotParameters: Dim Parameters As CAE.Xyplot.PlotParameters = theSession.XYPlotManager.NewPlotParameters() 'Passing the arrayRecord-Array to the Plot Parameters Parameters.SetRecords(records) 'Create a new Plot with the Parameters object: Dim plot1 As CAE.Xyplot.Plot = theSession.XYPlotManager.PlotRecords(Parameters)
As I said, I haven't tried it out, it's some copy and pasting from my code snippets but I hope this helps.
Thanks once again..... Yes its work fine with c# also...
I have one more query regarding the same, can I plot 2 graphs in one window means I need to plot two graphs in same window for example one between time and distance and other between acceleration and velocity. I am able to plot in separate windows but not in the same window.
If I understood correctly,
the "ViewPortIndex" of the PlotParameters object should be what you are looking for.
So if you have i.e. "Side by SIde" view enabled, it should be possible to plot one Graph to ViewPortIndex 0 and one Graph to ViewPortIndex 1.
'Create some PlotParameters: Dim Parameters As CAE.Xyplot.PlotParameters = theSession.XYPlotManager.NewPlotParameters() 'Passing the first arrayRecord-Array to the Plot Parameters Parameters.SetRecords(records1) 'Setting the ViewPortIndex Parameters.ViewPortIndex =0 'Create a new Plot with the Parameters object: Dim plot1 As CAE.Xyplot.Plot = theSession.XYPlotManager.PlotRecords(Parameters) 'Now the Second Graph: Parameters.ViewPortIndex = 1 Parameters.SetRecords(records2) Dim plot2 As CAE.Xyplot.Plot = theSession.XYPlotManager.PlotRecords(Parameters)
Again I haven't tried it out...