User Tools

Site Tools


Sidebar

Multimedia

k23:k23.8:start

23.8.0 Component gb.chart

B0

If you want to present data graphically in an impressive way, then the chart component gb.chart is just the thing. Unfortunately, the component is not stable and not error-free. Nevertheless, simple but meaningful charts such as line charts can be created with just a few instructions. It may therefore be worth experimenting with this component. This is also true in view of the fact that the developer has announced that the component will be revised.

23.8.0.1 Chart class

The Chart class can be used like an object by creating a hidden instance if required. This class behaves like a read-only array. The Chart class represents a chart object that can be drawn in a DrawingArea or on a picture of type Picture. You can also constantly update the data - unlike most other chart libraries.

You can create the class:

Dim hChart As Chart
hChart = New Chart()

You can then define the values of selected chart properties:

With hChart
  .Title = "Temperature time diagram (Berlin 2020)"
  ... 
End With

23.8.0.2 Properties

The Chart class has the following properties:

PropertyData typeDescription
BackGroundIntegerSets the background colour or returns the background colour for the chart background.
Colors_ColorsDefines the colours, for example, for the individual parts in a bar chart, pie chart or ring chart in an integer array.
CountDataSetsIntegerDetermines the number of data sets or returns the number of data sets to be used in the chart. For example, if there are 2 data sets in a “column” chart, 2 columns are drawn next to each other in different colours.
Headers_CHeadersDefines the names of the values on the x-axis in a string array.
HeightIntegerSets the chart height (pixels) or returns the value.
WidthIntegerSets the diagram width (pixels) or returns the value.
Legend_CLegendSets the descriptions in the diagram legend.
ProportionalBooleanDetermines or returns whether the fonts used in the diagram are drawn proportionally to the diagram size. The property is labelled as follows!
Title_CTitleSets the description of the chart with Chart.Title.Text.
TypeIntegerSets the chart type or returns the type. The type is determined by one of the ChartType constants.
XAxe_CXAxeDelivers an object that indicates how the X-axis is displayed in the chart.
YAxe_CYAxeDelivers an object that shows how the Y-axis is displayed in the diagram.

Table 23.8.0.2.1 : Properties of the Chart class

Here you can see an overview of the chart types, of which only a few provide usable (:!:) charts:

  • :!: CONST Columns As Integer = 0
  • :!: CONST ColumnsStacked As Integer = 1 - Only with corresponding data
  • CONST ColumnsPercent As Integer = 2
  • CONST ColumnsLineCombination As Integer = 3
  • CONST Pie As Integer = 10
  • CONST PieRings As Integer = 11
  • CONST PieOffSet1 As Integer = 12
  • CONST PieOffSet2 As Integer = 13
  • :!: CONST {Lines} As Integer = 20
  • :!: CONST LinesStacked As Integer = 21 - However, only with positive function values
  • CONST LinesPercent As Integer = 22
  • :!: CONST LinesSymbols As Integer = 23
  • :!: CONST Areas As Integer = 30
  • :!: CONST AreasStacked As Integer = 31
  • CONST AreasPercent As Integer = 32
  • :!: CONST AreasSymbols As Integer = 33
  • CONST Bars As Integer = 40
  • CONST BarsStacked As Integer = 41
  • CONST BarsPercent As Integer = 42
  • :!: CONST Plots As Integer = 50

23.8.0.3 Class _Colours

The colours for the individual parts, for example in a bar chart, pie chart or ring chart, are defined in an integer array. The _Colors virtual class has these properties:

PropertyData typeDescription
ValueInteger[ ]Determines the colours for the individual data (rows) in an integer array.
StyleIntegerDetermines whether the colours are read from a self-defined colour array or generated automatically. Style recognises the constants Custom and Auto.

Table 23.8.0.3.1 : Properties of the _Colors class

The _Colors class has an Add() method with which you can specify individual colours. If a data set consists of 3 values, then you also need 3 colours:

With Chart.Colors.Values
    .Add(Color.Red)
    .Add(Color.Blue)
    .Add(Color.Green)
  End With

Example:

Public Sub btnColors_Click()
  If btnColors.Text = ("Custom colors") Then
'--  The colours are read from a self-defined colour array
     Chart.Colors.Style = Chart.Colors.Custom 
     btnColors.Text = ("Default colors")
  Else
     Chart.Colors.Style = Chart.Colors.Auto '-- The colours are generated automatically
     btnColors.Text = ("Custom colors")
  Endif  
  DrawingArea1.Refresh()
End

23.8.0.4 Class _CHeaders

Use the class to define the names of the values on the x-axis in a string array. The _CHeaders virtual class has the following properties:

PropertyData typeDescription
CountIntegerDetermines the number of individual identifiers.
ValuesString[ ]Determines the different identifiers in a string array.

Table 23.8.0.4.1 : Properties of the _CHeaders class

The class has an Add() method with which you can specify individual identifiers. For example, if 4 values are to be displayed on the x-axis, then you also need 4 identifiers:

  With Chart.Headers.Values
    .Add("Frühjahr")
    .Add("Sommer")
    .Add("Herbst")
    .Add("Winter")
  End With
 
  Chart.Headers.Values = ["Frühjahr", "Sommer", "Herbst", "Winter"] '-- Alternative

23.8.0.5 Class _CLegend

The properties for the diagram legend are set in this class. The virtual class _CLegend has these properties:

PropertyData typeDescription
FontFontSets or returns the font.
PositionIntegerSpecifies the position where the legend is displayed. The value is provided by the two constants Align.Bottom and Align.Right. Other values are ignored.
TitleStringSets the title of the legend.
VisibleBooleanDetermines whether the legend is displayed or not. You can also read out the value.

Table 23.8.0.5.1 : Properties of the _CLegend class

Example:

'-- Defines the legend of the diagram.
    Chart.Legend.Title = "Information"
    Chart.Legend.Font = Font["Arial,+5"]   '-- Font for the legend - relative
    Chart.Legend.Position = Align.Bottom   '-- Alternative: Align.Right
    Chart.Legend.Visible = True

23.8.0.6 Class _CTitle

The _CTitle virtual class has three properties that you can use to describe the font, the text and the visibility for the diagram title:

PropertyData typeDescription
FontFontSets or returns the font.
TextStringSets the diagram heading. You can also read out the value.
VisibleBooleanSets whether the diagram heading is displayed or not. You can also read out the value.

Table 23.8.0.6.1 : Properties of the _CTitle class

Example:

'-- Visibility, title and font of the diagram
    Chart.Title.Visible = True
    Chart.Title.Text = "Spannung-Zeit-Diagramm"
    Chart.Title.Font = Font["Arial,24"] '-- Font for the title - absolute in px

23.8.0.7 Class _CXAxe

The properties of the x-axis (abscissa) of the diagram are set via its properties. The virtual class _CXAxe has these properties:

PropertyData typeDescription
AutoScaleBooleanSpecifies with True that the x-axis is labelled automatically.
FontFontSets or returns the font.
MinValueFloatSets or returns the minimum value on the x-axis. The default is 0.
MaxValueFloatSets or returns the maximum value on the x-axis. The default is 100.
StepFloatSets or returns the step size on the x-axis.
VisibleBooleanSpecifies whether the x-axis should be displayed or not. You can also read out the value.

Table 23.8.0.7.1 : Properties of the _CXAxe class

23.8.0.8 Class _CYAxe

The properties of the y-axis (ordinate) of the diagram are set via the class properties. The virtual class _CYAxe has these properties:

PropertyData typeDescription
AutoScaleBooleanSpecifies with True that the y-axis is labelled automatically.
FontFontSets or returns the font.
MinValueFloatSets or returns the minimum value on the y-axis. The default is 0.
MaxValueFloatSets or returns the maximum value on the y-axis. The default is 100.
StepFloatSets or returns the step size on the y-axis.
ShowIntervalLinesBooleanSpecifies whether horizontal lines - parallel to the x-axis - should be displayed. The default is True.
VisibleBooleanSpecifies whether the y-axis should be displayed. You can also read out the value.

Table 23.8.0.8.1 : Properties of the _CYAxe class

Example:

Chart.YAxe.AutoScale = False
Chart.YAxe.MinValue = 0
Chart.YAxe.MaxValue = 5
Chart.YAxe.Step = 1
Chart.YAxe.ShowIntervalLines = False
Chart.YAxe.Visible = True

Note:

A complete project for a line-symbol chart that uses selected classes of the gb.chart component can be found in the next chapter. The special feature is that the data to be displayed is read from an SQLite database table in three series!

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.8/start.txt · Last modified: 09.03.2024 by emma

Page Tools