ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Date time plotting wrongly in X-axis
Posted by Ariffin Hasan on Mar-03-2011 14:51
Attachments:
Hi

I am using ChartDirector for quite some time now but recently discovered i am having
error
in plotting DateTime values on the X-axis. Using .Net 2.0

Data being plotted:
data0X(0) = CDate("1/20/2011 12:15:00 PM")
data0X(1) = CDate("1/20/2011 12:30:00 PM")
data0X(2) = CDate("1/20/2011 12:45:00 PM")
data0X(3) = CDate("1/20/2011 1:30:00 PM")
data0X(4) = CDate("1/20/2011 6:00:00 PM")
data0X(5) = CDate("1/20/2011 6:30:00 PM")
data0X(6) = CDate("1/28/2011 10:00:00 AM")

I get 7 point in the graph but wrong date and time. Please find attached the graph image.
The values plotted are:
1. 20/01/11 12:15:00
2. 21/01/11 19:52:00
3. 23/01/11 03:30:00
4. 24/01/11 11:07:00
5. 25/01/11 18:45:00
6. 27/01/11 02:22:00
7. 28/01/11 10:00:00

Only the first and last record appears to be correct. I think I am doing something wrong
or missing something because when there are lots of points the above issue does not
happen. I have attached the aspx file and vb code behind. Would appreciate your advice

cheers
Ariffin
samplegraph.png
samplegraph.aspx
samplegraph.aspx

651 bytes
    
samplegraph.aspx.vb
Imports ChartDirector
Partial Class zzsamplegraph
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CreateGraph1(WebChartViewer1)
    End Sub

    Protected Sub CreateGraph1(ByVal viewer As ChartDirector.WebChartViewer)

        Dim data0X(6) As Date
        data0X(0) = CDate("1/20/2011 12:15:00 PM")
        data0X(1) = CDate("1/20/2011 12:30:00 PM")
        data0X(2) = CDate("1/20/2011 12:45:00 PM")
        data0X(3) = CDate("1/20/2011 1:30:00 PM")
        data0X(4) = CDate("1/20/2011 6:00:00 PM")
        data0X(5) = CDate("1/20/2011 6:30:00 PM")
        data0X(6) = CDate("1/28/2011 10:00:00 AM")

        Dim c As XYChart = New XYChart(1005, 550)
        c.setBackground(&HFFFFFF, &H0)
        
        c.addTitle("Date Time", "Arial Bold", 10).setMargin2(0, 0, 10, 0)
      
        Dim plotArea As PlotArea = c.setPlotArea(100, 50, 780, 350, -1, -1, _
            Chart.Transparent, c.dashLineColor(&H444444, &H101), -1)

        c.setClipping()
      
        Dim legendBox As LegendBox = c.addLegend(10, 540, False, "Arial", 8)
        legendBox.setAlignment(Chart.BottomLeft)
        legendBox.setBackground(Chart.Transparent, Chart.Transparent)

        c.xAxis().setMargin(15, 15)
        c.xAxis().setLabelStyle("Arial Bold", 8, &H0, 90)
        c.xAxis().setMultiFormat(Chart.StartOfDayFilter(), "<*font=Arial Bold*>{value|dd-mm-yy hh:nn}", Chart.AllPassFilter(), "{value|dd-mm-yy}") ' hh:nn

        c.xAxis.setTitle("Date Time", "Arial Bold", 8)
        
        c.yAxis().setLabelStyle("Arial Bold", 8)
        c.yAxis().setTitle("Data", "Arial Bold", 8).setAlignment(Chart.TopLeft)
        c.yAxis().setColors(&H6666, &H6666, &H6666, &H6666)

        ' Add the first data series
        Dim layer0 As LineLayer = c.addLineLayer2()
        layer0.setXData(data0X)
        layer0.setXData2(data0X(0), data0X(data0X.Length - 1))
        layer0.setLineWidth(1)
        
        Dim data0Y() As Double = {12, 12, 12, 12, 12, 12, 328.9293}
        
        layer0.addDataSet(data0Y, -1, "Date Time - Data").setDataSymbol(3, 9) '&H6666
        

        'If strXAxis = "RAW_DATETIME" Then
        '    If myUtil.isDate(myUtil.SQLDate(txtDate.Text)).Length > 0 And myUtil.isDate(myUtil.SQLDate(txtDate2.Text)).Length > 0 Then
        '        Dim minval As Double = Chart.CTime(CDate(myUtil.SQLDate(txtDate.Text) & " " & txtFromTime.SelectedTime.ToString("HH:mm")))
        '        Dim maxval As Double = Chart.CTime(CDate(myUtil.SQLDate(txtDate2.Text) & " " & txtToTime.SelectedTime.ToString("HH:mm")))
        '        'c.xAxis.setLinearScale(minval, maxval)
        '        c.xAxis.setDateScale(minval, maxval, 86400)
        '    End If
        'Else
        '    If txtX2Min.Text.Length > 0 And txtX2Max.Text.Length > 0 Then
        '        c.xAxis.setLinearScale(CDbl(txtX2Min.Text), CDbl(txtX2Max.Text))
        '    End If
        'End If

        'If txty1Min.Text.Length > 0 And txty1Max.Text.Length > 0 Then
        '    c.yAxis.setLinearScale(CDbl(txty1Min.Text), CDbl(txty1Max.Text))
        'End If

        

        'Output the chart
        viewer.Image = c.makeWebImage(Chart.PNG)
        ' Include tool tip for the chart
        viewer.ImageMap = c.getHTMLImageMap("", "", _
            "title='{dataSetName} - Y({value}), X({x|dd-mm-yyyy hh:nn})'")
        viewer.Visible = True

    End Sub
End Class

  Re: Date time plotting wrongly in X-axis
Posted by Peter Kwan on Mar-03-2011 23:53
Hi Anffin.

In your code, you use:

        layer0.setXData(data0X)
        layer0.setXData2(data0X(0), data0X(data0X.Length - 1))

The first line means to use the 7 values in data0X as the x-coordinates of the 7 data points. The second line means to spread the data points evenly between the two values data0X(0) and data0X(data0X.Length - 1). These two lines are contradicting. ChartDirector will use the last line to position the data points.

To solve the problem, please remove the second line. In this way, chartDirector will use the first line to position the data points, which should be your intention.

Hope this can help.

Regards
Peter Kwan

  Re: Date time plotting wrongly in X-axis
Posted by Ariffin Hasan on Mar-04-2011 00:23
Hi Peter

Thanks for pointing that out. It solves the problem but since I remove that line, I need your
input to achieve the following requirement.

The line was done for the intention to allow user to set the min and max value scaling of
the X-axis when data is displayed.

For instance this dataset example we use, since 5 points are on 20/01/2011, use may want
to see these 6 point clearly so they may set the min and max value of the X-axis as
follows:

Min = 20/01/2011 00:00
Max = 21/01/2011 00:00

This should load the graph with the 6 points spread out and of course the last point wont
be in view since its more than the max value.

How do I achieve this now?

  Re: Date time plotting wrongly in X-axis
Posted by Peter Kwan on Mar-04-2011 16:01
Hi Ariffin,

To set the x-axis scale, please use Axis.setDateScale. For example:

c.xAxis().setDateScale(startDate, endDate)

Hope this can help.

Regards
Peter Kwan

  Re: Date time plotting wrongly in X-axis
Posted by Ariffin Hasan on Mar-04-2011 16:20
Thanks Peter.....this should resolve the problem we are encountering.

cheers
Ariffin