How to format axis in highchart - vb.net

I am creating a simple chart using the HighCharts .Net API:
Dim sFontFamily As String = "fontFamily: 'inherit'"
Dim oChart As DotNet.Highcharts.Highcharts = New DotNet.Highcharts.Highcharts("SearchCount")
With oChart
.InitChart(New DotNet.Highcharts.Options.Chart With {.Style = sFontFamily, .Height = 250, .DefaultSeriesType = DotNet.Highcharts.Enums.ChartTypes.Line})
.SetOptions(New GlobalOptions With {.Global = New DotNet.Highcharts.Options.Global With {.UseUTC = False}})
.SetTitle(New Title With {.Style = sFontFamily, .Text = "Search Count"})
.SetXAxis(New XAxis With {.Labels = New XAxisLabels With {.Style = sFontFamily}, .Title = New XAxisTitle With {.Style = sFontFamily, .Text = "Month"}})
.SetYAxis(New YAxis With {.Labels = New XAxisLabels With {.Style = sFontFamily}, .Title = New YAxisTitle With {.Style = sFontFamily, .Text = "Searches"}})
.SetCredits(New Credits With {.Enabled = False})
.SetTooltip(New Tooltip With {.Style = sFontFamily})
.SetSeries(New Series() With {.Name = "this year", .Data = New Data(oData)})
'display a legend so user knows what graphs represent
.SetLegend(New Legend With {.Style = sFontFamily, .Enabled = True})
litHighChartSearchCount.Text = oChart.ToHtmlString()
End With
For convenience here is the rendered result: https://jsfiddle.net/d063mhoL/
And the data passed to the Series looks like this:
If you check the Fiddle you will see the data on the Y-Axis is numeric, when I want it to be a string of the month name, can anyone help?

I needed to set the categories for the axis, like so:
.SetXAxis(New XAxis With {.Categories = sCategories.ToArray, .Labels = New XAxisLabels With {.Style = sFontFamily}, .Title = New XAxisTitle With {.Style = sFontFamily, .Text = "Month"}, .Type = AxisTypes.Datetime})
sCategories is a list(of string) containing the months

Related

Google Calendar Add multiple events at same time

I'm trying to add/update multiples event at same time in Google Calendar, in the example below I've to execute 1 by 1, but I want to use only one .Execute...
Sometimes I've to update 30-50 events at same time and every .Execute takes aprox. 1 second each.
I also tried to make a UpdateRequest list but I couldn't execute them at same time, I had to execute 1 by 1.
Private Sub AddEvents()
Dim newEvent1 As New [Event]() With {
.Summary = "Event1",
.Description = "Desc1",
.Start = New EventDateTime() With {.DateTime = DataHora, .TimeZone = TimeZone},
.End = New EventDateTime() With {.DateTime = DateAdd(DateInterval.Hour, 1, DataHora), .TimeZone = TimeZone},
.Reminders = New [Event].RemindersData() With {.UseDefault = True},
.ColorId = CorEvento
}
Dim newEvent2 As New [Event]() With {
.Summary = "Event2",
.Description = "Desc2",
.Start = New EventDateTime() With {.DateTime = DataHora, .TimeZone = TimeZone},
.End = New EventDateTime() With {.DateTime = DateAdd(DateInterval.Hour, 1, DataHora), .TimeZone = TimeZone},
.Reminders = New [Event].RemindersData() With {.UseDefault = True},
.ColorId = CorEvento
}
Dim request1 As EventsResource.UpdateRequest = service.Events.Update(newEvent1, RetornaCalendario(), EventID1)
request1.Execute()
Dim request2 As EventsResource.UpdateRequest = service.Events.Update(newEvent2, RetornaCalendario(), EventID2)
request2.Execute()
End Sub

Access added (sub) control in VB .NET

With this code I dynamicly add a panel with two panels inside (a header and a data panel). Within the Data panel there is also a label that I like to access.
Now I like to access the label inside the data panel but can't reach it with:
test_label.text = "this a second test"
Here the dynamicaly added panels
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newPanelMain As Panel = New Panel With {
.Location = New Point(200, 500),
.Name = "test",
.Size = New Size(500, 500)
}
Dim newPanelHeader As Panel = New Panel With {
.Name = newPanelMain.Name & "_header",
.BackColor = Color.Orange,
.Dock = DockStyle.Top,
.Height = 50
}
newPanelMain.Controls.Add(newPanelHeader)
Dim newPanelData As Panel = New Panel With {
.Name = newPanelMain.Name & "_data",
.Dock = DockStyle.Fill,
.BorderStyle = BorderStyle.FixedSingle
}
newPanelMain.Controls.Add(newPanelData)
Dim newPanelSize As Panel = New Panel With {
.Name = newPanelMain.Name & (("_size")),
.BackColor = Color.Red,
.Height = 20,
.Width = 20,
.Location = New Point(newPanelData.Width - 20, newPanelData.Height - 20)
}
newPanelData.Controls.Add(newPanelSize)
Dim newLabel As Label = New Label With {
.Text = "This is a test",
.Name = newPanelMain.Name & (("_label")),
.Location = New Point(0, 0),
.AutoSize = True
}
newPanelData.Controls.Add(newLabel)
Me.Controls.Add(newPanelMain)
End Sub
Declare newLabel as a member variable:
Private newLabel As Label
So you can use this code:
Me.newLabel = New Label With {
.Text = "This is a test",
.Name = newPanelMain.Name & (("_label")),
.Location = New Point(0, newPanelHeader.Height + 10),
.AutoSize = True
}
newPanelData.Controls.Add(Me.newLabel)
And then change its .Text property using:
Me.newLabel.Text = "this a second test"
In a different situation (e.g. if you have multiple Labels created at runtime) remember that you can use Control.ControlCollection class:
CType(CType(Me.Controls("test"), Panel).Controls("test_data"), Panel).Controls("test_label").Text = "this is a third test"

Generate qrcodes and print as mailing labels in crystal reports

I have a routine that generates qrcodes and stores them in a folder. What I needed was to print them as mailing labels in the crystal reports identifying the desired quantity of each one. What is the best way to do this? Thanks
Sub GeraQRCode(valor As String)
Dim options = New QrCodeEncodingOptions With {.DisableECI = True, .CharacterSet = "UTF-8", .Width = 250, .Height = 250}
Dim writer = New BarcodeWriter()
writer.Format = BarcodeFormat.QR_CODE
writer.Options = options
Dim qr = New BarcodeWriter()
qr.Options = options
qr.Format = ZXing.BarcodeFormat.QR_CODE
Dim result = New Bitmap(qr.Write(valor))
result.Save(Server.MapPath("~\QRCode\" & Trim(valor) & ".png"))
End Sub

How to fill a DataGridViewComboBoxColumn?

Sorry if this is something that should be obvious, but this is my first project using VB.NET, and some things are still beyond me.
I'm trying to setup a combobox inside a DataGridView but I keep getting
System.ArgumentException: DatagridviewComboBoxCell value not valid
I've been googling this for 2 hours now and to me it seems I'm setting up thing correctly, but probably something is amiss.
Dim imageCol As DataGridViewImageColumn
Dim checkCol As DataGridViewCheckBoxColumn
Dim col As DataGridViewColumn
Dim comboCol As DataGridViewComboBoxColumn
Dim ds As DataSet
Dim som As New SomStructure
Dim somministrazioni() As SomStructure = {}
With dgvListaAttivita
.Columns.Clear()
.AutoGenerateColumns = False
.ReadOnly = False
.EditMode = DataGridViewEditMode.EditOnEnter
.CausesValidation = False
somministrazioni.Clear
ds = getSomministrazioni(codevalue, Today())
If ds IsNot Nothing Then
For Each row As DataRow In ds.Tables(0).Rows
som.idOspite = row(0)
som.nomeOspite = row(1)
som.descrizioneSomministrazione = row(2)
som.idOperatore = row(3)
som.nomeOperatore = row(4)
som.preparata = False
somministrazioni.Add(som)
Next
End If
.DataSource = somministrazioni
imageCol = New DataGridViewImageColumn
imageCol.Width = 25
imageCol.ImageLayout = DataGridViewImageCellLayout.Normal
imageCol.Description = "delete"
imageCol.Image = My.Resources.note
.Columns.Add(imageCol)
col = New DataGridViewColumn
col.DataPropertyName = "descrizioneSomministrazione"
col.HeaderText = "Somministrazione"
col.ValueType = GetType(String)
col.CellTemplate = New DataGridViewTextBoxCell
col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
col.ReadOnly = True
.Columns.Add(col)
comboCol = New DataGridViewComboBoxColumn
Dim dt As DataTable = dsOperatori.Tables(0)
comboCol.DataSource = dt
comboCol.DisplayMember = "display"
comboCol.ValueMember = "idoperatore"
comboCol.DataPropertyName = "idOperatore"
comboCol.HeaderText = "Operatore"
comboCol.ValueType = GetType(Integer)
comboCol.CellTemplate = New DataGridViewComboBoxCell
comboCol.Width = 150
.Columns.Add(comboCol)
checkCol = New DataGridViewCheckBoxColumn
checkCol.DataPropertyName = "preparata"
checkCol.HeaderText = "P."
checkCol.ValueType = GetType(Boolean)
checkCol.CellTemplate = New DataGridViewCheckBoxCell
checkCol.Width = 20
.Columns.Add(checkCol)
End With
As I understand it it should be like this:
comboCol.DataSource = dt
comboCol.DisplayMember = "display"
comboCol.ValueMember = "idoperatore"
specifies the datasource and key/display values of the comboboxes in the column
comboCol.DataPropertyName = "idOperatore"
Is the name of the column linked to both the DataSource of the DataGridView and the ValueMember of the ComboBox, and that should display different selections on different rows.
If I remove the DataPropertyName from the code I don't get the error anymore, but I also get empty comboboxes.
Try commenting out the template line:
comboCol = New DataGridViewComboBoxColumn
Dim dt As DataTable = dsOperatori.Tables(0)
comboCol.DataSource = dt
comboCol.DisplayMember = "display"
comboCol.ValueMember = "idoperatore"
comboCol.DataPropertyName = "idOperatore"
comboCol.HeaderText = "Operatore"
comboCol.ValueType = GetType(Integer)
'comboCol.CellTemplate = New DataGridViewComboBoxCell
comboCol.Width = 150
.Columns.Add(comboCol)

How to reload Chart in VB NET

I have this code to load chart in Windows form program. It is placed in button click event handler. When I click the button first time chart is displayed OK. But on second click it will give me error "A chart element with the name 'Series1' could not be found in the 'SeriesCollection'." please see in code.
I'm new to VB not to mention charts and cannot figure out how to fix that so I can click the button any time(s) to reload the chart. Thanks a lot for any advice.
Dim pp As String = "J:\UCP\ApplicationsProgramming\MainDB.accdb"
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & pp & ";Persist Security Info=False;"
Dim tblFields As String = "SELECT Type, COUNT([Zone]) as CountZone FROM Faults GROUP BY Type "
Dim conn As New OleDbConnection(strConn)
Dim oCmd As New OleDbCommand(tblFields, conn)
Dim oData As New OleDbDataAdapter(tblFields, conn)
Dim ds As New DataSet
conn.Open()
oData.Fill(ds, "Faults")
conn.Close()
'''''''''''''''''''''''''''''
'~~> SET DATA SOURCE <~~'
'''''''''''''''''''''''''''''
Chart1.DataSource = ds.Tables("Faults")
''''''''''''''''''''''''''''''''
'~~> WORKING WITH CHARTAREA <~~'
''''''''''''''''''''''''''''''''
Dim CArea As ChartArea = Chart1.ChartAreas(0)
CArea.BackColor = Color.White
CArea.ShadowColor = Color.Red
CArea.Area3DStyle.Enable3D = True
'~~> Formatting X Axis
CArea.AxisX.MajorGrid.Enabled = False
CArea.AxisX.LabelStyle.Font = New System.Drawing.Font("Arial", _
10.0F, System.Drawing.FontStyle.Italic)
'~~> Formatting Y Axis
CArea.AxisY.MajorGrid.Enabled = False
CArea.AxisY.LabelStyle.Format = ""
CArea.AxisY.Interval = 0.1
''''''''''''''''''''''''''''
'~~> WORKING WITH TITLE <~~'
''''''''''''''''''''''''''''
'~~> Adding a Title
Dim T As Title = Chart1.Titles.Add("Fault Types")
'~~> Formatting the Title
With T
.ForeColor = Color.Black
.BackColor = Color.White
'~~> Setting Font, Font Size and Bold/Italicizing
.Font = New System.Drawing.Font("Arial", 11.0F, System.Drawing.FontStyle.Bold)
.BorderColor = Color.Black
.BorderDashStyle = ChartDashStyle.NotSet
End With
'''''''''''''''''''''''''''''
'~~> WORKING WITH SERIES <~~'
'''''''''''''''''''''''''''''
////// NEXT LINE WILL GIVE FOLLoWING ERROR:
////// "A chart element with the name 'Series1' could not be found in the 'SeriesCollection'." //////////
Dim Series1 As Series = Chart1.Series("Series1") <<<<<<<<<<
'~~> Setting the series Name
Series1.Name = "Fault Types"
'~~> Assigning values to X and Y Axis
Chart1.Series(Series1.Name).XValueMember = "Type"
Chart1.Series(Series1.Name).YValueMembers = "CountZone"
'~~> Setting Font, Font Size and Bold
Chart1.Series(Series1.Name).Font = New System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Bold)
'~~> Setting Value Type
Chart1.Series(Series1.Name).YValueType = ChartValueType.Double
'~~> Setting the Chart Type for Display
'Chart1.Series(Series1.Name).ChartType = SeriesChartType.Radar
Chart1.Series(Series1.Name).ChartType = SeriesChartType.Pie
'~~> Display Data Labels
Chart1.Series(Series1.Name).IsValueShownAsLabel = True
'~~> Setting label's Fore Color
Chart1.Series(Series1.Name).LabelForeColor = Color.FloralWhite
'~~> Setting label's Format to %age
Chart1.Series(Series1.Name).LabelFormat = "" '"0.0%"
'~~> Setting the location for the chart
Chart1.Size = New System.Drawing.Size(865, 350)
The line Series1.Name = "Fault Types" changes the serie's name.
So, upon click, the next call to Dim Series1 As Series = Chart1.Series("Series1") will fail.
If you use only one serie, you should try Dim Series1 As Series = Chart1.Series(0)