Super 2d/3d Graph Library

Enhance your .NET application adding nice charts within minutes! Save time and money!


Example 52: XYZ surface databinding sample (to a DataGridView control)

This sampe code will plot a surface chart using data from a DataGridView.

 

Key aspects of this tutorial:

 

  • Change data in DataGridView and chart control will update automatically.

  • You can make a selection of cells in DataGridView and data will be highlighted in chart also.

  • You can rotate the chart in 3D moving the mouse while pressing left button.

  • You can move up/down any point using mouse (press CONTROL and drag the point in chart)

  • You can make a selection of points in chart pressing SHIFT and moving the mouse over.

 

Steps:

1. Create a new Windows application project (VB.NET)

2. Add Super 2d/3d Graph Library to the toolbox pallete and drag it to Form1.

3. Add a DataGridView control to the Form1.

4. Copy and paste de following code:

Form Code

Imports System.Drawing.Drawing2D
Imports
Super2d3dGraphLibrary

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  Dim rows As Integer = 20
 
Dim cols As Integer = 20
 
Dim hotspots(rows - 1) As ArrayList

  With DataGridView1
    .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
    .RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
    .Columns.Clear()
    For c As Integer = 1 To cols
      .Columns.Add("", c * 100)
    Next

    .Rows.Add(rows)

    Dim y As Integer = 0
    For r As Integer = 1 To rows
      .Rows(r - 1).HeaderCell.Value = CStr(r * 10)
      hotspots(r - 1) = New ArrayList
      For k As Integer = 1 To cols
        .Rows(r - 1).Cells(k - 1).Value = y
        y += Rnd() * 10 - 5
        If y < 0 Then y = 0
        hotspots(r - 1).Add("X-Axis = " & .Columns(k - 1).HeaderCell.Value & ", Z-Axis = " & .Rows(r - 1).HeaderCell.Value & ", Height = " & .Rows(r - 1).Cells(k - 1).Value)
      Next
    Next

  End With

  With Super2d3dGraph1
    ' Initialize chart control
    .AutoRefresh = False
    .LicenseeIdentifier = "PROF"
    .BackStyle = STYLEBACKGROUND.STYLEBACKGROUND_GRADIENT
    .WallsBackStyle = STYLEWALLBACKGROUND.STYLEWALLBACKGROUND_SOLID
    .WallsBackColorPrincipal = Color.White
    .ShowDataTable = False
    .ShowValues = False
    .ShowLegend = False
    .Style = STYLE2D3D.STYLE3D_XYZ_SURFACE
    .HotSpotTooltips = hotspots

    ' Set some look and feel properties
    .SurfaceGradientType = SURFACE_GRADIENT_TYPE.TWO_COLORS_HUE_GRADIENT
    .SurfaceGradientHueStart = New HsbColorUtil(0, 0.5, 1)
    .SurfaceGradientHueEnd = New HsbColorUtil(360, 0.5, 1)
    .SetAllSeriesLineStyle(New Pen(Color.Black))

    ' Y-Axis-format
    .ShowYAxis = True
    .YAxisTitle = "Y-Axis"
    .YAxisDividersCount = 5
    .YAxisNumericFormat = "0"

    ' X-Axis-format
    .ShowXAxis = True
    .XAxisTitle = "X-Axis"
    .XAxisNumericFormat = "0"
    .XAxisDividersCount = 5
    .ShowDividersX = True

    ' Z-Axis-format
    .ShowZAxis = True
    .ZAxisTitle = "Z-Axis"
    .ZAxisDividersCount = 5
    .ShowDividersZ = True
    .ZAxisNumericFormat = "0"

    ' New property to enable selection
    .HotSpotOutlineEnabled = True

    ' New properties for databinding
    .DataSource = DataGridView1
    .DataSourceMode = DATASOURCE_SCHEME.XZ_HEADERS_Y_CELLS

    ' Paint chart
    .RefreshChart()

End With

End Sub

End Class



Result:


 

License & Purchase Info


Current version: 14

Super 2d/3d Graph Library is available as:
-Standard License (99€)
-Premium License (149€)
-Enterprise License (299€)

Click here for more details & purchase

Contact Info


Feel free to contact us
for questions related to any of our products or custom .Net development. We usually respond in the same labor day.

Software Siglo XXI

Main support service: support@softwaresigloxxi.com

Sales and other enquiries: contact@softwaresigloxxi.com