Class

WebChart


Description

Displays data you provide in chart form of various types.

Events

Name

Parameters

Returns

Closed

ContextualMenuSelected

hitItem As WebMenuItem

Hidden

Opening

OverrideOptions

options As JSONItem

Pressed

dataset As ChartData, index As Integer

RequestedPicture

chart As Picture

Shown

Enumerations

WebChart.Modes

Modes

The various types of charts available.

Enum

Bar

Bubble

Doughnut

Line

Pie

PolarArea

Radar

Scatter

Stacked

Property descriptions


WebChart.AllowPopover

AllowPopover As Boolean

If True, a popover will be displayed when the user positions the mouse over items that have additional information.

The default value is True.


WebChart.AutoCalculateYAxis

AutoCalculateYAxis As Boolean

If True, the Y axis for Line and Bar charts will start at 0.

This property is True by default.


WebChart.Backdrop

Backdrop As WebPicture

The passed WebPicture that will automatically be drawn behind the chart data.

The following code assigns a jpg image to the Backdrop. The image has been added to the project. The code is in the Opening event.

Me.BackDrop = HouseImage

WebChart.ContextualMenu

ContextualMenu As WebMenuItem

If you assign a WebMenuItem to the control, it will be displayed when the user right-clicks the control.

On a WebPage, you can disable/remove the default contextual menu by an empty WebMenuItem class object to this property.

This code populates a contextual menu in the Shown event of the control.

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select Case hitItem.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebChart.ControlID

ControlID As String

Identifies the control on a per session basis.

This property is read-only.


WebChart.DatasetCount

DatasetCount As Integer

The number of datasets that have been added to the chart.

This property is read-only.


WebChart.DatasetLastIndex

DatasetLastIndex As Integer

The index of last dataset added to the chart.

This property is read-only.


WebChart.Enabled

Enabled As Boolean

When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.

In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.

Disable a button when a check box value changes:

If AllowSaveCheckBox.Value Then
  SaveButton.Enabled = True
Else
  AllowSaveButton.Enabled = False
End If

WebChart.GridColor

GridColor As ColorGroup

The color of the chart's grid.


WebChart.HasAnimation

HasAnimation As Boolean

If True, changes to chart data will result in animated updates to the chart.


WebChart.HasLegend

HasLegend As Boolean

If True, the chart's legend will be displayed.


WebChart.Height

Height As Integer

The height (in pixels) of the control.


WebChart.Indicator

Indicator As Indicators

The color scheme for the control.


WebChart.IsGridVisible

IsGridVisible As Boolean

Determines if the grid will be drawn or not.


WebChart.IsYAxisVisible

IsYAxisVisible As Boolean

Determines if the Y axis will be drawn or not.


WebChart.IsXAxisVisible

IsXAxisVisible As Boolean

Determines if the X axis will be drawn or not.


WebChart.LabelCount

LabelCount As Integer

The number of labels in the chart.

This property is read-only.


WebChart.LabelLastIndex

LabelLastIndex As Integer

The index of last label added to the chart.

This property is read-only.


WebChart.Left

Left As Integer

The position of the left side of the WebUIControl in pixels, relative to the web page.


WebChart.LegendColor

TextColor As ColorGroup

Gets or sets the color of the legend. The default value is black.

The following example sets the LegendColor.

Me.LegendColor = Color.Red

WebChart.LegendFontName

TitleFontName As String

Name of the font used to display the chart legend.

You can enter any font that is installed in the browser.

Tip

You can install fonts from Google as well.

This code sets the FontName property.

Me.LegendFontName = "Helvetica"

WebChart.LegendFontSize

LegendFontSize As Double

Point size of the font used to display the legend.

If you enter zero as the FontSize, your app will use the font size that works best for the platform on which it is running.

This code sets the font size to 16 points.

Me.LegendFontSize = 16

WebChart.LockBottom

LockBottom As Boolean

Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning web page.


WebChart.LockHorizontal

LockHorizontal As Boolean

LockHorizontal overrides LockLeft and LockRight. It allows you to proportionally lock a control's position to the center of its parent control (or web page).

For example, if you place a control in the center of the page and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebChart.LockLeft

LockLeft As Boolean

Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning web page.


WebChart.LockRight

LockRight As Boolean

Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning web page.


WebChart.LockTop

LockTop As Boolean

Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning web page.


WebChart.LockVertical

LockVertical As Boolean

LockVertical overrides LockTop and LockBottom. It allows you to proportionally lock a control's position to keep it centered within the parent control or web page.

For example, if you place a control in the center of the page, and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebChart.Mode

Mode As Modes

Indicates the type of chart the control is currently displaying.

Labels are required for a Bar chart to draw.

This example checks the mode of the chart:

If Chart1.Mode = WebChart.Modes.Bar then
  Chart1.Title = "Sales Bar Chart"
End If

WebChart.Name

Name As String

The name of the control.

This property is read-only.


WebChart.PanelIndex

PanelIndex As Integer

If the control has been placed on a WebTabPanel or WebPagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.

The first panel is numbered zero. If the control has been placed on a panel of a WebTabPanel or WebPagePanel control, it returns the panel number. If the control is not on a WebPagePanel or WebTabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.

If you are looking to change the currently selected panel (page/tab), use SelectedPanelIndex.

This code displays the panel index of the control that is on the page.

MessageBox(Me.SelectedPanelIndex.ToString)

WebChart.Page

Page As WebPage

Identifies the web page that contains the control.

This property is read-only.


WebChart.Parent

Parent As WebView

Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.

This property is read-only.


WebChart.PopoverBackgroundColor

PopoverBackgroundColor As ColorGroup

The background color of the chart's popover.


WebChart.TabIndex

TabIndex As Integer

The WebChart's control's position in the Tab Order. The control with a TabIndex of 0 is the first WebUIControl to get the focus when the page opens in the browser.

This example sets the control's TabIndex.

Me.TabIndex = 2

WebChart.Title

Title As String

The title of the chart.


WebChart.TitleColor

TitleColor As ColorGroup

Gets or sets the color of the title. The default value is black.

The following example sets the TitleColor.

Me.TitleColor = Color.Red

WebChart.TitleFontName

TitleFontName As String

Name of the font used to display the chart title.

You can enter any font that is installed in the browser.

Tip

You can install fonts from Google as well.

This code sets the TitleFontName property.

Me.TitleFontName = "Helvetica"

WebChart.TitleFontSize

TitleFontSize As Double

Point size of the font used to display the title.

If you enter zero as the FontSize, your app will use the font size that works best for the platform on which it is running.

This code sets the font size to 16 points.

Me.TitleFontSize = 16

WebChart.Tooltip

Tooltip As WebToolTip

Text of a message displayed as a tooltip.

The tip is displayed when the user places the mouse on the control and leaves it there.

This code in the Shown event of a Button sets the tooltip:

Me.Tooltip = "Save changes"

WebChart.Top

Top As Integer

The top of the control in local coordinates relative to the web page.


WebChart.Visible

Visible As Boolean

If True, the control is drawn. If False, it's not.

Hide a control based on a checkbox setting:

If ShowEmailCheckbox.Value Then
  EmailField.Visible = True
Else
  EmailField.Visible = False
End If

WebChart.Width

Width As Integer

The width (in pixels) of the web control.

This code in the Shown event handler increases the size of the control:

Me.Width = Me.Width + 50

Method descriptions


WebChart.AddDataset

AddDataset(dataset As ChartDataset)

Adds the dataset to the chart. Incompatible datasets are ignored.


WebChart.AddDatasetAt

AddDatasetAt(index As Integer, dataset As ChartDataset)

Adds the dataset to the chart at the index passed. Incompatible datasets are ignored.


WebChart.AddDatasets

AddDatasets(datasets() As ChartDataset)

Adds the array of datasets to the chart.


WebChart.AddLabel

AddLabel(name As String)

Adds the label to the chart.


WebChart.AddLabelAt

AddLabelAt(index As String, name As String)

Adds the label to the chart at the index passed.


WebChart.AddLabels

AddLabels(names() As String)

Adds the array of labels to the chart.


WebChart.Close

Close

Closes the chart.


WebChart.CSSClasses

CSSClasses

Returns the instance of WebCSSClasses for this control allowing you to add CSS classes to and remove CSS classes from the control.


WebChart.DatasetAt

DatasetAt(index As Integer) As ChartDataset

Returns the ChartDataset at the index passed.


WebChart.DataSets

DataSets() As Iterable

Allows iterating through all data sets.


WebChart.ExecuteJavaScript

ExecuteJavaScript(script As String)

Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.

The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the EcmaScript 6 documentation.

This code in the Pressed event of a Button displays an alert using JavaScript:

Me.ExecuteJavaScript("alert('Hello!');")

This code will select the text in a WebTextField (or WebTextArea):

WebTextField1.ExecuteJavascript("document.getElementById('" + _
  WebTextField1.ControlID + "_inner').select();")

WebChart.GotoURL

GotoURL(URL As String, inNewWindow As Boolean = False)

Opens the passed URL in place of the current web page or downloads a file. If InNewWindow is True, the browser is asked to open the URL in a new window.

If the browser has popup windows disabled and InNewWindow is True, the method silently fails and the page is not shown.

If InNewWindow is False, the running web app is replaced with the specified URL. If you want to display an external web site within your web app, use the WebHTMLViewer control.

Display a web site in a new popup window:

Me.GotoURL("http://www.wikipedia.org", True)

WebChart.LabelAt

LabelAt(index As Integer) As String

Returns the label at the index passed.


WebChart.Labels

Labels() As Iterable

Allows iterating through all labels.


WebChart.RemoveAllDatasets

RemoveAllDatasets

Removes all datasets from the chart.


WebChart.RemoveAllLabels

RemoveAllLabels

Removes all labels from the chart.


WebChart.RemoveDatasetAt

RemoveDatasetAt(index As Integer)

Removes the ChartDataset at the index passed.


WebChart.RemoveLabelAt

RemoveLabelAt(index As Integer)

Removes the label at the index passed.


WebChart.SetFocus

SetFocus

Sets the focus to the Control.

This code checks for a required value when a button is pressed:

If UserNameField.Text.IsEmpty Then
  MessageBox("Please enter your UserName.")
  UserNameField.SetFocus
  Return
End If

WebChart.Style

Style As WebStyle

Returns the WebStyle for the control.


Style(Assigns style As WebStyle)

Assigns the style to the control.

In this example, in any event of the control, set the text to bold:

Var style As New WebStyle
style.Bold = True
Me.Style = style

WebChart.ToPicture

ToPicture(width As Double = -1, height As Double = -1)

Creates a Picture from the the chart at the size specified by the width and height parameters. If these parameters are not specified, the Picture is created using the dimensions of the chart. The Picture is returned via the RequestedPicture event.


WebChart.UpdateBrowser

UpdateBrowser

Forces the current values of the control to be sent to the browser.

This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.

This code iterates through a RowSet of database rows, updates a ProgressBar and then forces the updated ProgressBar to be sent to the browser via UpdateBrowser.

ProgressBar1.MaximumValue = SalesData.RowCount
For Each row As DatabaseRow in SalesData
 AnalyzeSales(row)
 ProgressBar1.Value = ProgressBar1.Value + 1
 ProgressBar1.UpdateBrowser
Next

Event descriptions


WebChart.Closed

Closed

The control has been removed from the browser either because the page has closed or the control's Close method was called.


WebChart.ContextualMenuSelected

ContextualMenuSelected(hitItem As WebMenuItem)

Called when a contextual menu item is selected. This selected item is contained in hitItem.

This code populates a contextual menu in the Opening event of a WebToolbar:

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select Case hitItem.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebChart.Hidden

Hidden

The control is about to become no longer visible. This could be because the page is being closed, is being replaced as the foreground page by another page or because the control or a parent control's Visible property has been set to False.

Note

This event is equivalent to the DesktopWindow.Deactivated event in a desktop app.


WebChart.Opening

Opening

The control has been created and the page is opening but has not been sent to the browser yet.

The Opening event handler can be used to initialize non-visual properties and settings for controls.

In most cases, you should use the Shown event to initialize controls.


WebChart.OverrideOptions

OverrideOptions(options As JSONItem)

Allows you to override the built-in features of WebChart by modifying the Options parameter passed.

WebChart is based upon ChartJS. See the ChartJS website for details on the format of the data in the Options parameter.


WebChart.Pressed

Pressed(dataset As ChartData, index As Integer)

The user pressed on a part of the chart that represents data from the dataset.


WebChart.RequestedPicture

RequestedPicture(chart As Picture)

This event is called when the ToPicture method and is passed a Picture representing the chart.


WebChart.Shown

Shown

The control has appeared on the currently displayed page. This could be because its parent page just finished loading, its parent page has come to the foreground or the control is now visible having been previously invisible because it or its parent control's Visible property has been set to True.

Use the Shown event for initializing your controls or doing anything that would interact with other controls or user interface elements on the web page instead of the Opening event.

Note

This event is the web equivalent to the DesktopWindow.Activated event.

This code in the Shown event of a WebListBox adds 2 rows with 3 columns:

Me.RemoveAllRows
Me.AddRow("Row 1", "Bob", "Roberts")
Me.AddRow("Row 2", "Barb", "Reynolds")

This example sets the text of a label:

If Session.LoggedIn Then
  Me.Text = "Welcome!"
Else
  Me.Text = "Welcome, " + Session.UserName
End If

Notes

If you wish to set the background color of the chart, do so via the Style property.

Compatibility

Web projects on all supported operating systems.