I use the following code to programatically create a new display, add a trend, create a new dataset and then add the dataset to the trend.
The trend is created however the dataset comes up as invalid. To get it working, I open the trend to edit the calculation, click once in the expression box and then once in the column name box and then save. The problem seems to be that the column name is not being set when the dataset is created, making it invalid. If you remove all the code about creating the trend and just use the code to create the dataset, the same thing happens - if I manually try to add it to the trend, it says invalid dataset when I select it. I still need to click in the expression box and then the column name box to get it to work.
Code:Sub Add_DS_to_Trend()
Dim MyDatasets As Datasets
Dim MyDataset As PIExpressionDataset
Set NewDisplay = Application.Displays.Add("New Trend")
Set trnd = Application.ActiveDisplay.Symbols.Add(pbSymbolTrend)
trnd.Width = Application.ActiveDisplay.ViewWidth
trnd.Height = Application.ActiveDisplay.ViewHeight
Set MyDatasets = Application.ActiveDisplay.Datasets
Set MyDataset = MyDatasets.Add("NewCalcDataSet", Nothing, True, 1, True, pbDatasetPIExpression)
Set MyDataset = MyDatasets.GetDataset("NewCalcDataSet")
MyDataset.Expression = "'sinusoid'*2"
MyDataset.RefreshInterval = 3600
MyDataset.ColumnName = "Value"
MyDataset.Interval = "10m"
MyDatasets.SetDataset MyDataset
trnd.AddTrace "NewCalcDataSet.Value"
End Sub