Make the grid of chart control to begin at an even hour - vb.net

I am using a chart control which in x axis displays time, initialized as follows:
With Chart1.ChartAreas(0)
.AxisX.Minimum = 0
.AxisX.LabelStyle.Format = "HH:mm"
.AxisX.IntervalType = DateTimeIntervalType.Hours
.AxisX.Interval = 2
.AxisY.Minimum = 0
End With
Chart1.Series(0).IsXValueIndexed = True
Sometimes the data points start at an odd hour like the picture bellow
My question is how can I make the grid and labels begin at an even hour instead.
Thanks in advance.

OK I got it. I just removed the commands
.AxisX.Minimum = 0 in With...End With statement and
Chart1.Series(0).IsXValueIndexed = True
and now the grid always begins at an even hour automatically.

Related

How to plot a polyline between multiple points with vba

I am trying to plot a polyline between multiple points in vba into autocad. I have almost finished my code, but the thing is that the points may repeat themselves, as 2 lines can have the same starting point, and the points are nor in a sorted way.
I need to be able to addd all points even if they aren't sorted, cause I have to keep the order of the points I am tryint to plot.
I am getting this error:
Invalid Procedure or argument call
Set acadPol = acadDoc.ModelSpace.AddLightWeightPolyline(Points)
This is my code:
Points(1)=9736.242889: Points(2)=9954.553808
Points(3)=9718.429708: Points(4)=9936.874562
If acadDoc.ActiveSpace = acModelSpace Then
Set acadPol = acadDoc.ModelSpace.AddLightWeightPolyline(Points)
Else
Set acadPol = acadDoc.PaperSpace.AddLightWeightPolyline(Points)
End If
acadPol.Closed = False
acadPol.Update
End If
End If
Your code is incomplete but I notice you have started your coordinates list at index 1.
There are plenty of examples on the internet
Sub Example_AddLightWeightPolyline()
' This example creates a lightweight polyline in model space.
Dim plineObj As AcadLWPolyline
Dim points(0 To 9) As Double
' Define the 2D polyline points
points(0) = 1: points(1) = 1
points(2) = 1: points(3) = 2
points(4) = 2: points(5) = 2
points(6) = 3: points(7) = 2
points(8) = 4: points(9) = 4
' Create a lightweight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
ZoomAll
End Sub
As you can see, you need to start your coordinates array at index 0 and not 1.
Does this help?

vb chart second xaxis label offset

I am creating a VB.Net chart with date/time as the xAxis labels. It is working fine but what I want to do is sync the second label to a even hour boundary. The chart should have the first label as the first date/time in the dataset, but the labels following would then be on a 6 hour (00:00 - 06:00 - 12:00 - 18:00) boundry. I could also live with not having the first axis label as long as the rest were on a 6 (or 12, depending on the length of the data) hour boundary.
Current:
07:00-------13:00-------19:00-------01:00-------07:00-------13:00
What I'm after:
07:00--12:00-------18:00-------00:00-------06:00-------12:00
Chart as currently produced
I've got it... sort of.
For area As Integer = 0 To numLanes -1
myArea = New ChartArea("myArea" & area.ToString)
With myArea
.BackColor = mySetup.colorPlotBackground ' set from user preferences
.Area3DStyle.Enable3D = mySetup.is3D ' set from user preferences
.AxisX.LabelStyle.Format = "g"
.AxisX.Interval = 1
.AxisX.IntervalType = DateTimeIntervalType.Days
.AxisX.IntervalOffset = 0
.AxisX.IntervalOffsetType = DateTimeIntervalType.Hours ' Set the X value type of the displayed series to DateTime.
End With
cht.ChartAreas.Add(myArea)
Produces the attached chart.
Slightly Improved

Algorithm for finding end of a list (SAP GUI)

I'm writing a script that adds elements to a list in a SAP GUI screen. Now, it seems that when using SAP GUI, nothing "exists" unless it is actually on screen, so the first step involves finding the end of the list.
I accomplished this by scrolling though each element, and checking if it was blank.
Do While Not blank
If session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2,0]").Text = "" Then blank = True
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = i
i = i + 1
Loop
However, for very large existing lists, this takes a long time. I'm trying to figure out a way to find the end more quickly. Some truths/limitations I know:
I'm assuming I have no knowledge of the list length.
I cannot command the verticalScrollbar.position too far beyond the end of
the list. For ex. if the list contains 62 elements, .verticalScrollbar.Position = 100 will not work.
In the case of the above example, SAP does NOT throw an error. Nothing happens at all, and then next line of code executes.
All references to elements are with respect to their position on the screen. Ex, if I scroll down 5 positions, the 6th element of the overall list would actually indexed as 1.
On the other hand, verticalScrollbar.Position is absolute
I'm thinking of doing the following (in very psuedocode):
i = 0
do while scrolled = true
scrolled = false
a = GUIlist[0]
verticalScrollbar.Position = i + 1000
b = GUIlist[0]
'check to see the first element shown has changed
if a <> b then
scrolled = true
i = i + 1000
end if
loop
do while scrolled = true
scrolled = false
a = GUIlist[0]
verticalScrollbar.Position = i + 500
b = GUIlist[0]
if a <> b then
scrolled = true
i = i + 500
end if
loop
...and so on until I'm iterating i by one.
Is there a generally accepted better way of doing this kind of 'search'?
Any input is appreciated.
Thanks
My suggestion:
session.findById("wnd[0]").sendVKey 83
myPosition = session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position
do
if session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2,0]").Text = "" then exit do
myPosition = myPosition + 1
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = myPosition
loop
msgbox myPosition
Regards,
ScriptMan
Just to go to the end
max_scrollbar = session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Maximum ' Get the maximum scrollbar value
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = max_scrollbar ' Go to the end

VBA Excel Graphing Add time to X-Axis

I am graphing a trend for a pump for a day, I am getting a sample data every minuet
I got the graph all working but the problem I am running into is trying to get the time on the X-axis. There is a column that shows the time each sample data was taken, but when I tried to add it, it put the time for every point in the chart. Because I have 1440 points in the chart, it was just a blob of unreadable text, I removed that code and right now I am doing without. But I would like to figure it out.
'Chart for Monday
With wBM.ActiveSheet.ChartObjects.Add(Left:=300, Width:=300, Top:=10, Height:=300)
.Chart.SetSourceData Source:=wBM.ActiveSheet.Range("B1:B1440"), PlotBy:=xlColumns
.Chart.ChartType = xlLine
.Left = rngChart2.Left
.Top = rngChart2.Top
.Width = rngChart2.Width
.Height = rngChart2.Height
.Chart.HasTitle = True
.Chart.ChartTitle.Text = "Monday " & Monday
.Chart.HasLegend = False
End With
This is my code so far. In Column D has the time for each point so it would be "D1:D1440".
Is there a way to only have 1 label for every 60 points, or 120? So that I don't have such a blob of labels?
Starting with sample data that looks like this:
I ran this macro to hide all labels which 'location' is not multiple of 5
Sub formateDataLabels()
Dim chrt As Chart
Set chrt = ActiveChart
Dim cnt As Long: cnt = 1
For Each lbl In chrt.SeriesCollection(1).DataLabels
If cnt Mod 5 <> 0 Then
lbl.Text = ""
End If
cnt = cnt + 1
Next lbl
End Sub
Result:
Note that the current code is simply set up to run on the selected chart. Change the 5 to whatever you need such as 50 or 100 and adapt to your current chart.

Deleting empty Series out of Graph (with VBA)

I am trying to remove all empty series out of an Excel graph.
Dim isEmptySeries As Boolean
For Series = 1 To .SeriesCollection.count
.SeriesCollection(Series).ApplyDataLabels Type:=xlDataLabelsShowValue, AutoText:=True, LegendKey:=False
isEmptySeries = True
For i = 1 To .SeriesCollection(Series).points.count
If .SeriesCollection(Series).points(i).DataLabel.Text = 0 Then
.SeriesCollection(Series).points(i).HasDataLabel = False
Else
isEmptySeries = False
.SeriesCollection(Series).points(i).DataLabel.Font.Size = 17
End If
Next i
If isEmptySeries Then
.SeriesCollection(Series).Delete
End If
Next Datenreihe
The script fails at the ApplyDatalabels line ("Method SeriesCollection of Object Chart failed").
I believe that Excel shifts the Series indexes when one of the Series is deleted? Is that the case? It's the only explanation that I have for the error.
How else would I loop through the series and remove the ones that are empty?
In these sorts of situations try looping in reverse order
For i = .SeriesCollection(Series).points.count To 1 Step -1
That way the .Delete doesn't effect the item yet to be looped through