Create Heatmap and ContourSeries with Oxyplot - vb.net

I’m trying to display data from csv file as a combination of contour and heat maps. CSV file consists of three columns:
x;y;z
1;1;1
2;1;1
3;1;2
4;1;2
5;1;2
6;1;2
7;1;2
8;1;1
9;1;1
10;1;1
1;2;1
2;2;1
3;2;2
4;2;4
5;2;4
Etc…
After reading csv I convert it to arrays and use them as data source for OxyPlot HeatMapSeries and ContourSeries according t examples I was able to find. Unfortunately, they are only in C#. Hope, someone can help with VB. So far, I created below listing, however result does not represent the data I have in csv.
Dim dt_table As DataTable = csvToDatatable_2(Application.StartupPath & "\test.csv", ";")
Dim x(dt_table.Rows.Count - 1) As Double
Dim y(dt_table.Rows.Count - 1) As Double
Dim numbers(dt_table.Rows.Count - 1, 2) As Double
For i = 0 To dt_table.Rows.Count - 1
x(i) = CDbl(dt_table.Rows(i)(0))
y(i) = CDbl(dt_table.Rows(i)(1))
numbers(i, 0) = CDbl(dt_table.Rows(i)(0))
numbers(i, 1) = CDbl(dt_table.Rows(i)(1))
numbers(i, 2) = CDbl(dt_table.Rows(i)(2))
Next
Dim Plotmodel As New OxyPlot.PlotModel
Dim linearColorAxis As New OxyPlot.Axes.LinearColorAxis()
linearColorAxis.Palette = OxyPalettes.Rainbow(10)
Plotmodel.Axes.Add(linearColorAxis)
Dim heatmapseries1 As New OxyPlot.Series.HeatMapSeries
heatmapseries1.X0 = 0
heatmapseries1.X1 = 10
heatmapseries1.Y0 = 0
heatmapseries1.Y1 = 10
heatmapseries1.Interpolate = True
heatmapseries1.Data = numbers
Dim contourSeries1 As New OxyPlot.Series.ContourSeries()
contourSeries1.LineStyle = LineStyle.Solid
contourSeries1.StrokeThickness = 2
contourSeries1.ContourColors = {OxyColors.Aquamarine, OxyColors.Aqua, OxyColors.CadetBlue, OxyColors.Blue, OxyColors.Black, OxyColors.Red}
contourSeries1.RowCoordinates = x
contourSeries1.ColumnCoordinates = y
contourSeries1.Data = numbers
Plotmodel.Series.Add(heatmapseries1)
Plotmodel.Series.Add(contourSeries1)
PlotView1.Model = Plotmodel
Even shape of Contourseries is not square, as expected:

Related

Libreoffice Unable to fill ListBox because I could not declare the listbox righteously

I have a Listbox in my Calc Worksheet and I am trying to address it for filling it with data
DialogLibraries.LoadLibrary("Standard")
oDialog = CreateUnoDialog(DialogLibraries.Standard)
listBoxGruppe = oEvent.Source.Context.getControl("Drop_Down_5") 'oDialog.getControl("Drop_Down_5")
aItems = sheetb.getCellRangeByName(subStrRan).dataarray
Dim sItems(ubound(aItems))
For i = 0 To ubound(aItems)
sItems(i) = aItems(i)(0)
Next i
listBoxGruppe.addItems(sItems, 0)
oDialog.Execute()
However, it seems u need to call a certain Dialog, but idk what is the name of my Dialog for this scenario - this is how my code behind looks like
I think you don't need dialogs at this situation
dim RangeAddr as new com.sun.star.table.CellRangeAddress
RangeAddr.EndColumn = 1
RangeAddr.EndRow = Cell.CellAddress.Row
RangeAddr.Sheet = 2
RangeAddr.StartColumn = 1
RangeAddr.StartRow = 0
dim initParam(0) as new com.sun.star.beans.NamedValue
initParam(0).Name="CellRange"
initParam(0).Value = RangeAddr
CellRangeListSource = doc.createInstanceWithArguments("com.sun.star.table.CellRangeListSource", initParam )
listBoxGruppe.setListEntrySource CellRangeListSource

CATIA VB.net create chanfer by selected face

I'm trying to create a chamfer using pre selected faces in a macro. But i'm no having much sucess
what I have tried:
The faces are previously selected.
chamfer2 = shapeFactory1.AddNewChamfer(reference1, catTangencyChamfer, catLengthAngleChamfer, catNoReverseChamfer, 1, 45.0#)
Dim Num_Faces As Integer = selection1.count
Dim Faces_ref(Num_Faces)
For i = 1 To Num_Faces
Dim MyBRepName = (selection1.Item(i).Value.Name)
MyBRepName = Replace(MyBRepName, "Selection_", "")
MyBRepName = Left(MyBRepName, InStrRev(MyBRepName, "));"))
MyBRepName = MyBRepName + ");WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)"
MsgBox(MyBRepName)
reference1 = Part1.CreateReferenceFromName(MyBRepName)
chamfer1.AddElementToChamfer(reference1)
Next
the error appears here:
chamfer1.AddElementToChamfer(reference1)
Try to remove brackets from reference1 like this:
chamfer1.AddElementToChamfer reference1

Array Out of bounds error VB

Sorry for the terrible wording on my last question, I was half asleep and it was midnight. This time I'll try to be more clear.
I'm currently writing some code for a mini barcode scanner and stock manager program. I've got the input and everything sorted out, but there is a problem with my arrays.
I'm currently trying to extract the contents of the stock file and sort them out into product tables.
This is my current code for getting the data:
Using fs As StreamReader = New StreamReader("The File Path (Is private)")
Dim line As String = "ERROR"
line = fs.ReadLine()
While line <> Nothing
Dim pos As Integer = 0
Dim split(3) As String
pos = products.Length
split = line.Split("|")
productCodes(productCodes.Length) = split(0)
products(products.Length, 0) = split(1)
products(products.Length, 1) = split(2)
products(products.Length, 2) = split(3)
line = fs.ReadLine()
End While
End Using
I have made sure that the file path does, in fact, go to the file. I have looked through debug to find that all the data is going through into my "split" table. The error throws as soon as I start trying to transfer the data.
This is where I declare the two tables being used:
Dim productCodes() As String = {}
Dim products(,) As Object = {}
Can somebody please explain why this is happening?
Thanks in advance
~Hydro
By declaring the arrays like you did:
Dim productCodes() As String = {}
Dim products(,) As Object = {}
You are assigning size 0 to all your arrays, so during your loop, it will eventually try to access a position that haven't been previously declared to the compiler. It is the same as declaring an array of size 10 Dim MyArray(10) and try to access the position 11 MyArray(11) = something.
You should either declare it with a proper size, or redim it during execution time:
Dim productCodes(10) As String
or
Dim productCodes() As String
Dim Products(,) As String
Dim Position as integer = 0
'code here
While line <> Nothing
Redim Preserve productCodes(Position)
Redim Preserve products(2,Position)
Dim split(3) As String
pos = products.Length
split = line.Split("|")
productCodes(Position) = split(0)
products(0,Position) = split(1)
products(1,Position) = split(2)
products(2,Position) = split(3)
line = fs.ReadLine()
Position+=1
End While

VB.NET add a decimal Point to Series

The following Function creates multiple series for a graph.
Function createSeries(ByVal fileNames() As String, ByVal intValXAxis As Integer, ByVal intValYAxis As Integer) As Series()
Dim ChartSeries(fileNames.Count) As Series
Dim i As Integer = 0
For Each filename In fileNames
ChartSeries(i) = New Series
ChartSeries(i).ChartType = SeriesChartType.FastLine
ChartSeries(i).ChartArea = "ChartArea1"
If filename.Contains("NOK") = True Then
ChartSeries(i).Color = Color.Red
ChartSeries(i).BorderWidth = 3
Else
ChartSeries(i).Color = Color.Green
End If
Dim fileReader = My.Computer.FileSystem.OpenTextFileReader(filename)
Do
Dim strCache() As String = Split(fileReader.ReadLine(), ";")
ChartSeries(i).Points.AddXY(strCache(intValXAxis - 1), strCache(intValYAxis - 1))
ChartSeries(i).ToolTip = filename
Loop Until fileReader.EndOfStream = True
i += 1
Next
Return ChartSeries
End Function
The problem I have is, that the Y-Values of the Series I create are mostly something like that: 0,09440104 or 0,1757813. I need these Values shown on the graph as they are, but the zero's got removed and the Y-Point-Values are : 9440104 or 1757813
I tried to format them with "Globalization" before adding them to the Series, but it doesn't solved the problem.
Just to be clear: I want the numbers as shown above(0,09440104 and 0,1757813) to be the Y-values of the points.
How can i solve the problem?
Thanks in advance.
By default, En-US culture will read your comma "," as thousand separator and thus taking your data as > 0 rather than < 0.
You have two options: change the culture or change the string format. If all your numbers are less than 1000 (or, to be more precise, not having . as thousand separator), I recommend simply to replace , with .
Dim strCache() As String = Split(fileReader.ReadLine(), ";")
Dim repStrX = strCache(intValXAxis - 1).Replace(",",".")
Dim repStrY = strCache(intValYAxis - 1).Replace(",",".")
ChartSeries(i).Points.AddXY(repStrX , repStrY)
Or, if they are having value more than 1000 (or, again, to be more precise, not having . as thousand separator), without specifying the culture, you could also use Replace with some tricks: making use of non-existing character as intermediate value to flip between . and , in the original string.
Dim strCache() As String = Split(fileReader.ReadLine(), ";")
Dim repStrX = strCache(intValXAxis - 1).Replace(",","G").Replace(".",",").Replace("G",".")
Dim repStrY = strCache(intValYAxis - 1).Replace(",","G").Replace(".",",").Replace("G",".")
ChartSeries(i).Points.AddXY(repStrX , repStrY)

Issue with blank entry in array

I have an array that can either have 6 or 7 values, the code below shows how I can have 6 or 7 values:
Dim AB(1 To 7)
AB(1) = "1-P"
AB(2) = "1-L"
AB(3) = "1-E"
AB(4) = "1-I"
AB(5) = "1-O"
AB(6) = "1-T"
If TeachingTool.teacherInPlYes = True Then
AB(7) = "1-R"
End If
Once the array has been populated I search the current sheet for the calues in the array and populate a listbox with there cell positions, however because there is a blank space in the array it pulls me back alot of unwanted data for some reason and I can't figure out why. I have tried use Dim AB(1 To 6 or 7) but that didn't work. So some information on this issue would be helpful, thanks
Use ReDim. That way you can dimension the array accordingly. Example:
If TeachingTool.teacherInPlYes = True Then
ReDim AB(1 To 7)
AB(7) = "1-R"
Else
ReDim AB(1 to 6)
End If
AB(1) = "1-P"
AB(2) = "1-L"
AB(3) = "1-E"
AB(4) = "1-I"
AB(5) = "1-O"
AB(6) = "1-T"