Tutorial 3: Create an area/bar combo chart (VB.NET)
« on: February 04, 2016, 12:48:16 PM »
This example is a little more complicated because two charts are involved and this time we'll customize many aspects of each chart. I demonstrate the power of Crossing Charts for .NET to combine two instances of the chart library and produce one fusioned chart (area + bar types).

1. Create a new Windows application project (VB.NET)
2. Add Crossing Charts to the toolbox pallete and drag it to Form1
3. Copy and paste de following code:

Code: [Select]
Imports CrossingChartsLibrary
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim arrBarChartValues(0) As ArrayList
        Dim strItems(50) As String
        ' Configure main chart (area chart)
        arrBarChartValues(0) = New ArrayList
        With CrossingCharts1
            .AutoRefresh = False              ' Increase speed
            .Style = STYLE2D3D.STYLE2D_STACKED_AREA
            .Title = "Area/Bar Combo Chart"
            For k As Integer = 0 To 50
                arrBarChartValues(0).Add(Rnd() * 25000 + 25000)
                strItems(k) = k
            Next
            .Series = arrBarChartValues       ' Assign values to area chart
            .ItemsLegend = strItems
            .SeriesLegend = New String() {"Team 1 score"}
            .SeriesColor = New Color() {Color.LightYellow}
            .XAxisDividersCount = 10          ' # of items in the X-axis
            .ShowDividersX = False             ' Hide vertical lines
            .YAxisScaleMode = SCALEMODE.SCALEMODE_FIXED
            .YAxisScaleMaximum = 50000
            .YAxisScaleMinimum = 0
            .YAxisTitle = "Score"
            .XAxisTitle = "Game"
            .ShowValues = False               ' Hide values over chart
            .ShowLegend = True
            .LegendAlignment = STYLEALIGNMENT.STYLEALIGNMENT_BOTTOM_CENTER
            .LegendText = ""                  ' Hide legend's title
            .ShowDataTable = False
        End With
        ' Now create the second chart (bar or column chart)
        Dim oBarChart As New CrossingChartsLibrary.CrossingCharts
        Dim arrSeries(0) As ArrayList, arrItems(15) As String
        arrSeries(0) = New ArrayList
        Dim p As Integer = Rnd() * 50 + 50
        With oBarChart
            .AutoRefresh = False
            For k As Integer = 0 To 15
                arrSeries(0).Add(p)
                p += Rnd() * 10 - 5
                If p < 50 Then
                    p += 25
                ElseIf p > 99 Then
                    p -= 25
                End If
                arrItems(k) = k
            Next
            .Series = arrSeries
            .Style = STYLE2D3D.STYLE2D_BAR
            .YAxisLocation = STYLEYAXISLOCATION.STYLEYAXISLOCATION_RIGHT
            .YAxisDividersCount = 10
            .YAxisScaleMode = SCALEMODE.SCALEMODE_FIXED
            .YAxisScaleMinimum = 0
            .YAxisScaleMaximum = 150
            .SeriesLegend = New String() {"Team 2 score"}
            .ItemsLegend = arrItems
            .ShowValues = False
            .ShowDividersX = True
            .XAxisDividersCount = 10
            .XAxisLabelsRotated = True
            .ShowXAxis = True
        End With
        ' Add the second chart to current chart
        CrossingCharts1.ChartAdd(oBarChart)
        ' Draw the composition
        CrossingCharts1.AutoRefresh = True
    End Sub  ' Form_Load
End Class

Results:

« Last Edit: February 16, 2016, 09:09:02 AM by CrossingCharts »