Getting and setting information about the data and its display

There are several methods for getting and setting information about data in a graph in a DataWindowControl at runtime.

The methods listed in Table 8-1 get and set information about the data.

Table 8-1: Get and set methods for data in graphs

Method

Information provided or set

GetCategoryName

The name of a category, given its number

GetCategoryNumber

The number of a category, given its name

GetDataDateTime

The value of a data point, given its series and position

GetDataDouble

The value of a data point, given its series and position

GetDataStyle

The color, fill pattern, and other visual properties of a specified data point

GetSeriesDataCount

The number of data points in a series

GetSeriesName

The name of a series, given its number

GetSeriesNumber

The number of a series, given its name

GetSeriesStyle

The color, fill pattern, and other visual properties of a specified series

SetDataStyle

The color, fill pattern, and other visual properties for a specific data point

SetSeriesStyle

The color, fill pattern, and other visual properties for a series

You can also use properties to get information about the graph.

Table 8-2: Common properties for graphs in DataWindows

Property

Information provided

CategoryCount

The number of categories in a graph

Created

Whether the graph has been created (drawn)

GraphObjectUnderMouse

The part of the graph that is under the mouse pointer

SeriesCount

The number of series in a graph

Type

The type of graph, using the GraphType enumeration

Using point and click

The GraphObjectUnderMouse property uses the GraphObjectAtPointer structure to hold information about the part of the graph under the mouse. GraphObjectAtPointer has three fields:

Example

This example uses the GraphObjectUnderMouse property to display a tooltip showing the part of the graph that is under the mouse as it hovers over the graph.

When you create a DataWindow object using the Graph presentation style, the graph is given the name gr_1. If you insert a graph into a DataWindow of a different style, the default name for the graph is also gr_1.

The example declares an instance of the GraphicObjectGraph object named gobGraph. Then it uses the DataWindowControl’s GetObjectByName method to get the type of gr_1 and convert it to a GraphicObjectGraph object assigned to gobGraph.

If the type of the graph object under the mouse is Category, the string displayed by the tooltip is “Category: ” followed by the category name for the current datapoint. If the type is a Series, the string displayed by the tooltip is “Series” followed by a colon and the name of the series. All graphs have at least one implicit series. When you create a graph with no explicit series, a series is created with an empty string as the series name.

If the type is Data, scatter graphs need to be handled differently, because they have no Category, and the X and Y coordinates are specified as X and Y values of the GraphAxis enumerated type. Other graph types always have a category.

The code is in the MouseMove event for a DataWindowControl.

[Visual Basic]
Private Sub dw1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dw1.MouseMove

 Dim gobGraph As Sybase.DataWindow.GraphicObjectGraph
 Dim s As String
 Dim xData As String
 Dim yData As String
 Dim seriesName As String
 Dim dataPoint As Integer

 Try
  gobGraph = CType(dw1.GetObjectByName("gr_1"), _
     Sybase.DataWindow.GraphicObjectGraph)
  seriesName =  _
     gobGraph.GraphObjectUnderMouse.SeriesName
  dataPoint = gobGraph.GraphObjectUnderMouse.DataPoint

  s =  _
    gobGraph.GraphObjectUnderMouse.ObjectType.ToString

  Select Case s
    Case "Category"
    s = s + ": " + gobGraph.GetCategoryName(dataPoint)

    Case "Series"
   ' Check for explicit series
    If Trim(seriesName).Length > 0 Then
      s = s + ": " + seriesName
    End If

    Case "Data"
    ' scatter graphs have x, y and no category
    If gobGraph.Type =  _
       Sybase.DataWindow.GraphType.Scatter Then
       Try
         xData = gobGraph.GetDataDouble(seriesName,  _
          dataPoint, Sybase.DataWindow.GraphAxis.X)
         yData = gobGraph.GetDataDouble(seriesName,  _
          dataPoint, Sybase.DataWindow.GraphAxis.Y)
         If Trim(seriesName).Length > 0 Then
           s = "Series: " + seriesName
         End If
         s = s + "   Value: (" + xData.ToString + ","   _
          + yData.ToString + ")"
       Catch
         s = s + "   Value: <unavailable>"
       End Try
    Else
      ' every other graph type has a category at least
      s = "Category: " +  _
        gobGraph.GetCategoryName(dataPoint)

   ' Check for explicit series
      If Trim(seriesName).Length > 0 Then
        s = " Series: " + seriesName
      End If

      ' Axis values are either DateTime or Double.
      ' No method to determine datatype, so test for
      ' DateTime first. If not DateTime, throw an
      ' exception and handle as Double.
      Try
        s = s + "   Value: " + _
          CStr(gobGraph.GetDataDateTime(seriesName, _
          dataPoint, Sybase.DataWindow.GraphAxis.Y))
      Catch ex As Exception
        Try
          s = s + "   Value: " + _
           CStr(gobGraph.GetDataDouble(seriesName,  &
           dataPoint, Sybase.DataWindow.GraphAxis.Y))
        Catch ex2 As Exception
          s = s + "   Value: <unavailable>"
        End Try
      End Try
    End If
  End Select

  ' turn off tool tip if not on interesting part of graph
    If s = "Graph" Then
      tipGraph.Active = False
    Else
      tipGraph.Active = True
      tipGraph.SetToolTip(dw1, s)
    End If
  Catch ex As Exception
  ' ignore tooltip if there is an exception 
  ' (like no DataWindow object)
  End Try
End Sub