OWC chChartTypeScatterLineMarkers X Axis


Kevin Humphreys

Hi There,
I have a simple line chart below where on the X axis I need dates and on the
Y axis I need values.
The report works however on the X axis the date values are displayed as
Numeric values intead of date formats.
E.G. 01/01/07 displays as 39083, 04/01/2007 displays as 39086 etc. How can I
display these as the actual dates?

Below is the code for the Chart Series.

Response.Buffer = True
Response.ContentType = "image/gif"

'SQL Server connection string:
Dim ConnectionString As String = "Connection String"
'SQL command to find number of datapoints:
Dim CountText As String = "Get Record Count of Query"
'SQL command to get the datapoints:
Dim CommandText As String = "Get Date and Integer Field"

'Define the database connection object:
Dim myConnection As New SqlConnection(ConnectionString)
'Define the command object to find number of datapoints:
Dim myCount As New SqlCommand(CountText, myConnection)
'Define the command object to get the datapoints:
Dim myCommand As New SqlCommand(CommandText, myConnection)

'Define Data Reader object:
Dim DataReader1 As SqlDataReader
'i = index variable (used to populate array)
'NumPoints = integer representing number of datapoints from database
'aX = array containing X values
'aY = array containing Y values
Dim i
Dim NumPoints
Dim aX
Dim aY

'Define chart and series objects, as used in OWC chart model:
Dim Chart1, Chart1_Series1

'Open the database connection

'Step 1: Find number of datapoints and return value
'in "NumPoints" variable:
NumPoints = myCount.ExecuteScalar()

'Response.Write(NumPoints & "#")

'Redimension arrays according to number of datapoints
ReDim aX(NumPoints - 1)
ReDim aY(NumPoints - 1)

'Step 2: Get the datapoints and return X and Y values
'in aX and aY arrays:
DataReader1 = myCommand.ExecuteReader()
i = 0
While DataReader1.Read
aX(i) = DataReader1.GetValue(0)
aY(i) = DataReader1.GetValue(1)
i = i + 1
End While

'For i = 0 to NumPoints - 1
' Response.Write(aX(i) & "|" & aY(i) & "#")
'Next i

'Close the database connection

'Create a new chartspace:
ChartSpace1 = New Owc.ChartSpace
'Create a new chart within ChartSpace1:
Chart1 = Chartspace1.Charts.Add(0)
'Add a new dataseries within Chart1:
Chart1_Series1 = Chart1.SeriesCollection.Add(0)
'Define Chart1_Series1 as "scatter" (XY) diagram,
'with lines and markers:
Chart1_Series1.Type = _

'Name the dataseries (name appears in Legend):
Chart1_Series1.SetData(OWC.ChartDimensionsEnum.chDimSeriesNames, _
'Populate the X and Y values from array:
Chart1_Series1.SetData(OWC.ChartDimensionsEnum.chDimXValues, _
OWC.ChartSpecialDataSourcesEnum.chDataLiteral, aX)
Chart1_Series1.SetData(OWC.ChartDimensionsEnum.chDimYValues, _
OWC.ChartSpecialDataSourcesEnum.chDataLiteral, aY)

'Format the chartspace elements.
With ChartSpace1
'.Border.Color = Chartspace1.Constants.chColorNone
End With

'Format the chart elements.
With Chart1
'.SeriesCollection(0).Interior.Color = "Rosybrown"
'.PlotArea.Interior.Color = "Wheat"
.HasLegend = True
.Legend.Position = _
.HasTitle = True
.Title.Caption = "Preactor Planned V Acutal Trend Analysis"
.Axes(0).HasTitle = True
.Axes(0).Title.Caption = "Planned V Actual %"
.Axes(1).HasTitle = True
.Axes(1).Title.Caption = "Date"
End With

'Return the new chart in GIF format.
Response.BinaryWrite(Chartspace1.GetPicture("gif", 500, 400))

Thanks In Advance,
Kevin Humphreys.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question