locked
Wrong Date RRS feed

  • Question

  • Hi everyone,

    I'm having a problem with a chart. I'm creating a the serie using the following code:
    private Series criaSerieHumidade(int sn, DateTime begin, DateTime end) 
      ArrayList valuesList = dbClass.getValuesList(sn, begin, end); 
     
      Series serie = new Series("Temperature"); 
      serie.ChartType = SeriesChartType.Line; 
     
      foreach (Value value in valuesList ) 
      { 
       serie.Points.AddXY(value.time, value.temperature); 
      } 
     
       serie.Color = Color.Blue; 
       serie.MarkerStyle = MarkerStyle.Circle; 
       serie.MarkerSize = 5
       serie.MarkerColor = Color.White; 
       serie.MarkerBorderColor = Color.Blue; 
       serie.MarkerBorderWidth = 1
     
       serie.BorderWidth = 3
                 
       serie.IsXValueIndexed = true
     
       serie.XValueType = ChartValueType.Time; 
     
       return serie; 

    Everything is working fine at this point.

    However, when I add a new point to the existing serie the date appears wrong. The hour is fine but the date not. It appears as 1899-12-30 + correct hour.

    Does anybody knows what it might be the problem?
    Is there a way to make a refresh of the chart?
    Friday, March 13, 2009 11:34 AM

Answers

  • Based on the attached XML, your last data point has only Time but no Date part (prior to the decimal point):

        <DataPoint XValue="0.68888888888888888" YValues="25.12" /> 

    As you can see all other data points XValues start with 39885 and you should have something similar in the last point.  

    Alex.

    http://blogs.msdn.com/alexgor
    Saturday, March 14, 2009 1:26 AM

All replies

  • I can't see anything wrong with your code. Please embed an image of the chart and also attach chart XML data, which you can get by calling Chart.Serializer.Save method. Please make sure there is no any sensitive data in there!

    Alex.
    http://blogs.msdn.com/alexgor
    Friday, March 13, 2009 3:05 PM
  • Chart before adding a new point:
    img1.gif

    Chart after adding a new point:
    img2.gif

    Xml File:
    <Chart BackColor="WhiteSmoke" Size="475, 165" BackGradientStyle="TopBottom" BackSecondaryColor="White" BorderlineColor="26, 59, 105" BorderlineWidth="2" BorderlineDashStyle="Solid"
      <Series> 
        <Series Name="Temperatura" XValueType="Time" IsXValueIndexed="True" YValueType="Double" ChartType="Line" ChartArea="Area" Color="Red" BorderWidth="3" MarkerStyle="Circle" MarkerColor="White" MarkerBorderColor="Red"
          <Points> 
            <DataPoint XValue="39885.676388888889" YValues="25.12" /> 
            <DataPoint XValue="39885.678472222222" YValues="25.12" /> 
            <DataPoint XValue="39885.682638888888" YValues="25.12" /> 
            <DataPoint XValue="39885.68472222222" YValues="25.12" /> 
            <DataPoint XValue="39885.686805555553" YValues="25.12" /> 
            <DataPoint XValue="0.68888888888888888" YValues="25.12" /> 
          </Points> 
          <EmptyPointStyle Color="Red" BorderDashStyle="DashDot" MarkerStyle="Cross" MarkerSize="7" MarkerColor="LightGray" MarkerBorderColor="Black" /> 
        </Series> 
      </Series> 
      <ChartAreas> 
        <ChartArea BackColor="Gainsboro" BackGradientStyle="TopBottom" BackSecondaryColor="White" ShadowColor="Transparent" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" Name="Area"
          <CursorX IsUserEnabled="True" IsUserSelectionEnabled="True" /> 
          <CursorY IsUserEnabled="True" IsUserSelectionEnabled="True" /> 
          <AxisY IsLabelAutoFit="False" Title="ºC" TitleFont="Times New Roman, 12pt, style=Bold" LineColor="64, 64, 64, 64"
            <MajorGrid LineColor="64, 64, 64, 64" /> 
            <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" /> 
            <ScrollBar Size="10" LineColor="Black" /> 
          </AxisY> 
          <AxisX IsLabelAutoFit="False" LabelAutoFitStyle="IncreaseFont, DecreaseFont, WordWrap" LineColor="64, 64, 64, 64"
            <MajorGrid LineColor="64, 64, 64, 64" /> 
            <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" Format="yyyy-MM-dd HH:mm" /> 
            <ScrollBar Size="10" LineColor="Black" /> 
          </AxisX> 
        </ChartArea> 
      </ChartAreas> 
      <BorderSkin SkinStyle="Emboss" /> 
    </Chart> 




    Friday, March 13, 2009 4:49 PM
  • Based on the attached XML, your last data point has only Time but no Date part (prior to the decimal point):

        <DataPoint XValue="0.68888888888888888" YValues="25.12" /> 

    As you can see all other data points XValues start with 39885 and you should have something similar in the last point.  

    Alex.

    http://blogs.msdn.com/alexgor
    Saturday, March 14, 2009 1:26 AM
  • I solved the problem.
    I've done the following change on my code:

    The update code was like this:
    Control[] panel = splitContPrincipal.Panel2.Controls.Find("gbSensor_" + pk_sensor, true)[0].Controls.Find("panel_" + pk_sensor, true);
    (Chart)panel[0].Controls[0]).Series["Temperature"].Points.AddXY(time, valorT);

    Now I change to this and its working fine:
    Control[] panel = splitContPrincipal.Panel2.Controls.Find("gbSensor_" + pk_sensor, true)[0].Controls.Find("panel_" + pk_sensor, true);
    ((Chart)panel[0].Controls[0]).Series["Temperature"].Points.AddXY(time.ToOADate(), value); 

    Monday, March 16, 2009 10:52 AM