Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Line color remains limegreen even after changing it in code.

I am programmatically adding waveforms to a waveform chart.  The same function handles this addition for each of my 6 charts.  The first five charts work flawlessly.  Regarding the last chart, however, even after binding the waveforms to legend items whose colors are correct, the waveforms themselves are still lime green.  I've even traced the code and the line colors are correct when I mouseover the array of waveforms to check their properties.  At run time, the legend is correct and the waveform is wrong.  Any ideas?

 

 

Public Sub addChart(ByVal Chart As Byte, ByVal Index As Byte, ByVal axis As String, ByVal SeriesName As String, ByVal seriesCount As Byte) Try If seriesCount = 0 Then frmD.wfg0.Plots.Remove(frmD.WaveformPlot) frmD.wfg1.Plots.Remove(frmD.waveformPlot1) frmD.wfg2.Plots.Remove(frmD.waveformPlot2) frmD.wfg3.Plots.Remove(frmD.waveformPlot3) frmD.wfg4.Plots.Remove(frmD.waveformPlot4) frmD.wfgEmissions.Plots.Remove(frmD.WaveformPlot5) Dim cnt As Byte For cnt = 0 To 5 frmD.legPlotsA(cnt) = New Legend frmD.legPlotsB(cnt) = New Legend frmD.txtMessage.AppendText("legPlots(" & cnt & ") added." & vbNewLine) With frmD.legPlotsA(cnt) .Name = "legPlotsA" & cnt .Location = New Point(599, 4) .Size = New Point(151, 145) frmD.Controls.Add(frmD.legPlotsA(cnt)) frmD.legPlotsA(cnt).SendToBack() End With With frmD.legPlotsB(cnt) .Name = "legPlotsB" & cnt .Location = New Point(750, 4) ' <- Changed to 750 from 599. .Size = New Point(151, 145) frmD.Controls.Add(frmD.legPlotsB(cnt)) frmD.legPlotsB(cnt).SendToBack() End With If cnt > 0 Then frmD.legPlotsA(cnt).Visible = False frmD.legPlotsB(cnt).Visible = False End If Next cnt frmD.txtMessage.AppendText(vbNewLine) LoadColors() End If frmD.Waveform(seriesCount) = New WaveformPlot frmD.Waveform(seriesCount).LineColor = SeriesColors(Index) Select Case Chart Case 0 frmD.wfg0.Plots.Add(frmD.Waveform(seriesCount)) Case 1 frmD.wfg1.Plots.Add(frmD.Waveform(seriesCount)) Case 2 frmD.wfg2.Plots.Add(frmD.Waveform(seriesCount)) Case 3 frmD.wfg3.Plots.Add(frmD.Waveform(seriesCount)) Case 4 frmD.wfg4.Plots.Add(frmD.Waveform(seriesCount)) Case 5 frmD.wfgEmissions.Plots.Add(frmD.Waveform(seriesCount)) End Select frmD.Legend(seriesCount) = New LegendItem frmD.Legend(seriesCount).Text = SeriesName frmD.Legend(seriesCount).Source = frmD.Waveform(seriesCount) Select Case Index Case Is < 4 frmD.legPlotsA(Chart).Items.Add(frmD.Legend(seriesCount)) Case Is < 8 frmD.legPlotsB(Chart).Items.Add(frmD.Legend(seriesCount)) End Select Select Case Chart Case 0 If axis.Contains("L") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg0.YAxes(0) ElseIf axis.Contains("R") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg0.YAxes(1) End If Case 1 If axis.Contains("L") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg1.YAxes(0) ElseIf axis.Contains("R") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg1.YAxes(1) End If Case 2 If axis.Contains("L") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg2.YAxes(0) ElseIf axis.Contains("R") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg2.YAxes(1) End If Case 3 If axis.Contains("L") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg3.YAxes(0) ElseIf axis.Contains("R") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg3.YAxes(1) End If Case 4 If axis.Contains("L") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg4.YAxes(0) ElseIf axis.Contains("R") Then frmD.Waveform(seriesCount).YAxis = frmD.wfg4.YAxes(1) End If Case 5 If axis.Contains("L") Then frmD.Waveform(seriesCount).YAxis = frmD.wfgEmissions.YAxes(0) ElseIf axis.Contains("R") Then frmD.Waveform(seriesCount).YAxis = frmD.wfgEmissions.YAxes(1) End If End Select Catch ex As Exception MsgBox(ex.ToString) End End Try End Sub

 Chart.PNG

 

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 7
(4,416 Views)

Michael,

 

Thanks for posting your code.  I took a look at it and couldn't find anything glaringly incorrect, but I did have a few questions.

 

First, you have two methods that aren't defined here that may be interesting: LoadColors and SeriesColors.  What do these methods do?

Second, your method you posted takes in a Byte variable called seriesCount.  This is used when setting the LineColor of the waveform, so I was curious as to where that came from.

 

The line color is associated with the plot, so I'd check your plot generation code to make sure you added the proper code for your wfgEmissions plots as you have for your wfg0-4 plots.

Jonathan R.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 7
(4,391 Views)

Actually, series colors could be a function that returns a color now that you mention it.  LoadColors is a subroutine that populates an array of colors.  SeriesColors is the array so that I can choose colors appropriately for each chart.  SeriesCount is a counter that iterates through an array of plots and legend items.  While Index resets to zero for each chart, seriesCount continues to increment.  This is how I reference the next plot and legend item in the array each time I add a plot to a chart.

 

I copied one of the original charts and pasted it to create this chart...  All properties [i]should[/i] be the same..

Message Edited by SCXI and MS 2k3-VB.NET on 01-27-2010 08:24 AM
Message Edited by SCXI and MS 2k3-VB.NET on 01-27-2010 08:24 AM
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 3 of 7
(4,378 Views)

Michael,

 

Sorry about my last post, I was logged into a different account at the time.

 

One quick thing to check is to make sure that LoadColors is defining SeriesColors as an array with 6 elements and setting all 6 colors correctly.  If that wasn't modified, there could be a problem with referencing that element of the array.

 

I still haven't been able to reproduce the issue, so is there any way you could post more of your code?  It's good to see how you're creating the plots, but seeing how you are adding data to the plots would be helpful also.  A version of your code stripped down as much as possible that still reproduces the issue would be great.  If I can take the code and reproduce it, I have a better chance of seeing what is going wrong and whether or not it's a bug in our code or yours.  If you can't post it online publically, let me know and we can work out a way for you to get it to me.

Eric B.
National Instruments
0 Kudos
Message 4 of 7
(4,340 Views)

Public Sub LoadColors() SeriesColors(0) = Color.Red SeriesColors(1) = Color.LightBlue SeriesColors(2) = Color.Yellow SeriesColors(3) = Color.LimeGreen SeriesColors(4) = Color.Orange SeriesColors(5) = Color.Magenta SeriesColors(6) = Color.White SeriesColors(7) = Color.Gray SeriesColors(8) = Color.LightSeaGreen End Sub

 

If (Now.Second Mod Charts(0).UpdatePeriod = 0) Then If Charts(0).UpdateMode = "all" Then .wfg0.PlotYAppendMultiple(ChartData) Else chartModes = Split(Charts(0).UpdateMode, ",") For cnt = 0 To chartModes.Length - 1 If chartModes(cnt) = Mode(CurrentMode).ControlStep Then .wfg0.PlotYAppendMultiple(ChartData) Next End If End If If (Now.Second Mod Charts(1).UpdatePeriod = 0) Then If Charts(1).UpdateMode = "all" Then .wfg1.PlotYAppendMultiple(ChartData1) Else chartModes = Split(Charts(1).UpdateMode, ",") For cnt = 0 To chartModes.Length - 1 If chartModes(cnt) = Mode(CurrentMode).ControlStep Then .wfg1.PlotYAppendMultiple(ChartData1) Next End If End If If (Now.Second Mod Charts(2).UpdatePeriod = 0) Then If Charts(2).UpdateMode = "all" Then .wfg2.PlotYAppendMultiple(ChartData2) Else chartModes = Split(Charts(2).UpdateMode, ",") For cnt = 0 To chartModes.Length - 1 If chartModes(cnt) = Mode(CurrentMode).ControlStep Then .wfg2.PlotYAppendMultiple(ChartData2) Next End If End If If (Now.Second Mod Charts(3).UpdatePeriod = 0) Then If Charts(3).UpdateMode = "all" Then .wfg3.PlotYAppendMultiple(ChartData3) Else chartModes = Split(Charts(3).UpdateMode, ",") For cnt = 0 To chartModes.Length - 1 If chartModes(cnt) = Mode(CurrentMode).ControlStep Then .wfg3.PlotYAppendMultiple(ChartData3) Next End If End If If (Now.Second Mod Charts(4).UpdatePeriod = 0) Then If Charts(4).UpdateMode = "all" Then .wfg4.PlotYAppendMultiple(ChartData4) Else chartModes = Split(Charts(4).UpdateMode, ",") For cnt = 0 To chartModes.Length - 1 If chartModes(cnt) = Mode(CurrentMode).ControlStep Then .wfg4.PlotYAppendMultiple(ChartData4) Next End If End If If (Now.Second Mod Charts(5).UpdatePeriod = 0) Then If Charts(5).UpdateMode = "all" Then .wfgEmissions.PlotYAppendMultiple(ChartData5) Else chartModes = Split(Charts(5).UpdateMode, ",") For cnt = 0 To chartModes.Length - 1 If chartModes(cnt) = Mode(CurrentMode).ControlStep Then .wfgEmissions.PlotYAppendMultiple(ChartData5) Next End If End If

 

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 5 of 7
(4,322 Views)

Thanks for the additional bits of code.  The only thing that jumps out at me is that you're dynamically pulling the update mode and plotting based off of that, but since you're actually plotting the waveforms, that's probably not where the problem is.

 

Is there any way you could post your complete project?  I haven't been able to reproduce the issue on my end, and it's hard to see exactly what's going on without being able to look at the entire picture.  If you can't post it publically, let me know and we can work out a different way to transfer the code.

Eric B.
National Instruments
0 Kudos
Message 6 of 7
(4,298 Views)
I will try to make a mini project to see if I can reproduce it first.  The issue is only mildy annoying.  The project is fairly large and requires hardware configurations (at least virtual) to work.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 7 of 7
(4,280 Views)