Simulation & Probabilistic Analysis SDK
Add Distribution Fitting & Simulation Features to Your Applications

SPA SDK Help HomeLearn More About the SPA SDK

Creating Graphs

The SPA SDK allows to create a variety of graph types that can be saved as image files or displayed directly to the users of your applications. Before creating the graphs, you might want to specify some options affecting their appearance, such as the title, size, colors, and fonts. This can be done through the SPAApplication.GraphOptions property.

To actually create a graph, call the SPADataSet.Graph method with the following arguments:

Argument
name & type
Purpose
Accepted values
Description
graph
(SPAGraphType)
Graph type to create SPAGraphPdf Probability Density Function graph (for continuous data, use the SPAApplication.GraphOptions.NumBins property to control the number of input data histogram bins)
SPAGraphCdf Cumulative Distribution Function graph (for continuous data, use the SPAApplication.GraphOptions.NumBins property to control the number of empirical CDF bins)
SPAGraphSurvival Survival Function graph (for continuous data, use the SPAApplication.GraphOptions.NumBins property to control the number of empirical Survival Function bins)
SPAGraphHazard Hazard Function graph (available for continuous input data only)
SPAGraphCumHazard Cumulative Hazard Function graph (available for continuous input data only)
SPAGraphPP P-P Plot
SPAGraphQQ Q-Q Plot (available for continuous input data only)
SPAGraphDif Probability Difference graph
fitResults
(Variant)
Fitted distribution curves that should be displayed on top of the empirical data A single SPAFitResult object The graph will contain the empirical data and a single fitted distribution curve
An array of SPAFitResult objects The graph will contain the empirical data and one or more fitted distribution curves; you should set the SPAFitResult.ShowOnGraph property to True for those input array elements that should be displayed on the graph
Null The graph will only contain the empirical data

Depending on the SPAApplication.GraphOptions.Destination property value, the resulting graph can be saved to an image file, copied to the Clipboard, or returned as a Picture object directly to your application.

Example

Sub Test()
  Dim dataSet As New SPADataSet
  Dim fitResults() As Variant
  Dim count As Long
  Dim data(5) As Double
  Dim empty() As Double

  SPAApplication.Initialize

  ' specify the data
  data(0) = 1.5
  data(1) = 3.2
  data(2) = 9.6
  data(3) = 4.1
  data(4) = 7.8

  ' assign the data
  Call dataSet.Assign(SPADomainContinuous, SPADataSample, data, empty)

  ' run the fit  
  count = dataSet.Fit(SPADistAll, fitResults)

  ' show the two best fitting distributions
  If count > 0 Then fitResults(0).ShowOnGraph = True
  If count > 1 Then fitResults(1).ShowOnGraph = True

  ' specify the graph options
  SPAApplication.GraphOptions.Destination = SPABMPImage

  ' create the CDF graph and display it in a PictureBox control
  Set Picture1 = dataSet.Graph(SPAGraphCdf, fitResults)

  ' change the graph destination
  SPAApplication.GraphOptions.Destination = SPAJPGFile
  SPAApplication.GraphOptions.DestinationFileName = "c:\graph.jpg"

  ' change the number of histogram bins
  SPAApplication.GraphOptions.NumBins = 10

  ' create the empirical PDF graph (the histogram) and save it to a file
  Call dataSet.Graph(SPAGraphPdf, Null)
End Sub
  
Copyright © MathWave Technologies
www.mathwave.com