locked
X indexed does not seem to be working RRS feed

  • Question

  • Hi,
    I have the following chart in a page :

     

    <asp:Button ID="Button1" runat="server" Text="Submit" />

     

    <br />

     

    <asp:Chart ID="Chart1" runat="server"

     

    Height="532px" Width="751px" >

     

    <ChartAreas>

     

    <asp:ChartArea >

     

    </asp:ChartArea>

     

    </ChartAreas>

     

    </asp:Chart>

    When the button is clicked it displays the chart :

    Protected

     

    Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

     

    Dim values As New List(Of String)

     

    Dim i As Integer

     

    Dim strStoreProcName As [String] = "sp_ChannelData"

     

    Dim cmd As New SqlCommand(strStoreProcName)

    cmd.Parameters.Add(

    "@ChooseStartDate", SqlDbType.DateTime)

    cmd.Parameters.Add(

    "@ChooseEndDate", SqlDbType.DateTime)

    cmd.Parameters(

    "@ChooseStartDate").Value = ChooseStartDate.Text

    cmd.Parameters(

    "@ChooseEndDate").Value = ChooseEndDate.Text

    Chart1.Legends.Add(

    "Legend1")

    Chart1.ChartAreas.Add(

    "ChartArea1")

    i = 0

     

    For Each row As GridViewRow In GridView1.Rows

     

    If CType(row.Cells(0).FindControl("ChannelUnits"), CheckBox).Checked = True Then

    cmd.Parameters.Add(

    "@cmbcheck" & i, SqlDbType.SmallInt)

    cmd.Parameters(

    "@cmbcheck" & i).Value = GridView1.DataKeys(i).Value

    Chart1.Series.Add(

    "Series" & i + 1)

    Chart1.Series(

    "Series" & i + 1).XValueMember = "Date"

    Chart1.Series(

    "Series" & i + 1).XValueType = ChartValueType.DateTime

    Chart1.Series(

    "Series" & i + 1).YValueMembers = GridView1.DataKeys(i).Value

    Chart1.Series(

    "Series" & i + 1).ChartType = CType(row.Cells(1).FindControl("ChartType"), DropDownList).Text.ToString()

    Chart1.Series(

    "Series" & i + 1).YAxisType = CType(row.Cells(2).FindControl("Axis"), DropDownList).Text.ToString()

    Chart1.Series(

    "Series" & i + 1).ToolTip = "Date : #AXISLABEL\n#SERIESNAME: #VALY "

    Chart1.Series(

    "Series" & i + 1).IsXValueIndexed = False

    Chart1.Series(

    "Series" & i + 1).Name = CType(row.Cells(0).FindControl("ChannelName"), Label).Text.ToString()

     

    Else

     

    End If

    i = i + 1

     

    Next

     

    Dim dt As DataTable = GetData(cmd)

    GrdView.DataSource = dt

    GrdView.DataBind()

    Chart1.DataSource = dt

     

    End Sub


    But the statement below doesnt seem to be working :

    Chart1.Series(

    "Series" & i + 1).IsXValueIndexed = False

    Becuse I belive when I make this false it should display no data between 2 dates.

    i.e. if start date is 30/03/2009 and end data is 10/04/2009 and there is no data from 01/04/2009 - 05/04/2009 it should display a gap in the data in the y values.

    Does anyone know why this isnt working?

    Thanks

    Friday, May 1, 2009 12:56 AM

Answers

  • Hi Alex,

    I think I have this fixed now.

    I was converting the date and time in a stored procedure so I dont think the Chart was seeing these fields as datetime fields.

    I have removed the CONVERT statement from the stored proc and it seems to be working fine now.

    Thanks for your help.

    • Marked as answer by RupertRyan Sunday, May 3, 2009 9:57 PM
    Sunday, May 3, 2009 9:57 PM

All replies

  • IsXValueIndexed property is already set to False by default. Setting it to True will change how data point position is determined along the axis. In X value indexed mode the actual XValue is ignored and data point index is used to position points. X value is still used for labels.

    Check samples for more details...

    Alex.
    http://blogs.msdn.com/alexgor
    Friday, May 1, 2009 1:24 AM
  • Thanks Alex, Ive had a good look at the samples. When I add a series into the page and use a sqldatasource for the same data values i dont have thi sproblem.

    For some reason it is not doing it.

    If I have a data set like the following :

    Date,Time,Value
    30/03/2009,12:00,150
    30/03/2009,12:30,175
    30/03/2009,13:00,180
    05/04/2009,13:00,170

    It will not show zero values for the dates between 31/03/2009 - 04/04/2009.

    Do you know why this is?

    Thanks
    Friday, May 1, 2009 1:45 AM
  • I'm still not sure what you are trying to achieve. Setting IsXValueIndexed to False will not have any effect because it is a defualt value.

    Serialize your chart into XML file (Chart.Serializer.Save) and attach it to this thread. Also provide an image with comments what you want to achieve.

    Alex.


    http://blogs.msdn.com/alexgor
    Friday, May 1, 2009 4:01 AM
  • Hi Alex,

    Here is the xml from the chart:

    <Chart Width="751" Height="532">
    <Series>
    <Series Name="EkWh" XValueMember="Date" YValueMembers="20606" Legend="Legend1" XValueType="DateTime" ChartArea="ChartArea1" ToolTip="Date : #AXISLABEL\n#SERIESNAME: #VALY ">
    </Series>
    </Series>
    <ChartAreas>
    <ChartArea Name="ChartArea1">
    </ChartArea>
    </ChartAreas>
    <Legends>
    <Legend Name="Legend1">
    </Legend>
    </Legends>
    </Chart>

    And this is the data as displayed in gridview:

    DateTime20606
    30/03/2009 00:00:00 383.77600
    30/03/2009 00:30:00 384.00000
    30/03/2009 01:00:00 383.87200
    30/03/2009 01:30:00 383.88800
    30/03/2009 02:00:00 383.87200
    30/03/2009 02:30:00 383.84000
    30/03/2009 03:00:00 383.87200
    30/03/2009 03:30:00 383.88800
    30/03/2009 04:00:00 383.85600
    30/03/2009 04:30:00 383.76000
    30/03/2009 05:00:00 383.85600
    30/03/2009 05:30:00 383.95200
    30/03/2009 06:00:00 383.80800
    30/03/2009 06:30:00 383.68000
    30/03/2009 07:00:00 383.74400
    30/03/2009 07:30:00 383.72800
    30/03/2009 08:00:00 383.84000
    30/03/2009 08:30:00 383.69600
    30/03/2009 09:00:00 383.63200
    30/03/2009 09:30:00 383.56800
    30/03/2009 10:00:00 383.55200
    30/03/2009 10:30:00 383.42400
    30/03/2009 11:00:00 383.61600
    30/03/2009 11:30:00 383.39200
    30/03/2009 12:00:00 383.31200
    30/03/2009 12:30:00 383.29600
    30/03/2009 13:00:00 383.31200
    30/03/2009 13:30:00 383.29600
    30/03/2009 14:00:00 383.29600
    30/03/2009 14:30:00 383.29600
    30/03/2009 15:00:00 383.32800
    30/03/2009 15:30:00 383.24800
    30/03/2009 16:00:00 383.32800
    30/03/2009 16:30:00 383.29600
    30/03/2009 17:00:00 383.32800
    30/03/2009 17:30:00 383.37600
    30/03/2009 18:00:00 383.55200
    30/03/2009 18:30:00 383.36000
    30/03/2009 19:00:00 383.61600
    30/03/2009 19:30:00 383.29600
    30/03/2009 20:00:00 383.50400
    30/03/2009 20:30:00 383.44000
    30/03/2009 21:00:00 383.21600
    30/03/2009 21:30:00 383.93600
    30/03/2009 22:00:00 383.82400
    30/03/2009 22:30:00 383.64800
    30/03/2009 23:00:00 383.93600
    30/03/2009 23:30:00 383.42400
    31/03/2009 00:00:00 383.68000
    05/04/2009 17:00:00 410.00000



    It is not displaying anything between 31/03/2009 00:00:00 - 05/04/2009 16:30:00 in the chart even though I have set the xvaluetype as datetime.

    Do you know why this is?

    Sunday, May 3, 2009 8:10 PM
  • Hi Alex,

    I think I have this fixed now.

    I was converting the date and time in a stored procedure so I dont think the Chart was seeing these fields as datetime fields.

    I have removed the CONVERT statement from the stored proc and it seems to be working fine now.

    Thanks for your help.

    • Marked as answer by RupertRyan Sunday, May 3, 2009 9:57 PM
    Sunday, May 3, 2009 9:57 PM
  • Alex,

    I am having aproblem with DateTime.

    My chart is pretty simple: 2 series on Y-Axis as Column Chart and 1 series on Y2-Axis as Spline Chart.  All 3 series are on the same X-Axis which is DateTime.

    My problem is that the DateTime shows 11/07/2010 11:00AM or 11/07/2010 11:00PM regardless of the fact that the times in the database are actually like 11/07/2010 1:00PM, 11/07/2010 3:00PM, and 11/07/2010 5:00PM.  WHY???

    			<asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Height="768px" Width="1024px">
            <MapAreas></MapAreas>
            <Annotations></Annotations>
            <Titles>
             <asp:Title Text="Weather Forecast" BorderColor="Silver" BorderDashStyle="Solid" ShadowColor="Gray" ShadowOffset="6" Font="Trebuchet MS, 13pt, style=Bold" />
            </Titles>
            <legends>
    				     <asp:Legend Enabled="True" IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt" Alignment="Center" Docking="Bottom"></asp:Legend>
    			     </legends>
    			     <borderskin SkinStyle="Emboss" PageColor="White"></borderskin>
            <Series>
             <asp:Series ChartArea="ChartArea1" ChartType="Column" Name="Series1" 
              XValueMember="ForecastDateTime" IsXValueIndexed="true" YValueMembers="ApparentTemperature" 
              XValueType="DateTime" YValueType="Int32" YAxisType="Primary" LegendText="Temperature">
             </asp:Series>
             <asp:Series ChartArea="ChartArea1" ChartType="Column" Name="Series2" 
              XValueMember="ForecastDateTime" IsXValueIndexed="true" YValueMembers="DewPointTemperature" 
              XValueType="DateTime" YValueType="Int32" YAxisType="Primary" LegendText="Dew Point">          
             </asp:Series>
             <asp:Series ChartArea="ChartArea1" ChartType="Spline" Name="Series3" MarkerStyle="Circle"
              XValueMember="ForecastDateTime" IsXValueIndexed="true" YValueMembers="RelativeHumidity" 
              XValueType="DateTime" YValueType="Double" YAxisType="Secondary" LegendText="Humidity">
             </asp:Series>
            </Series>
            <ChartAreas>
             <asp:ChartArea Name="ChartArea1" ShadowOffset="10" ShadowColor="Gray">
              <AxisX Title="Forecast Date/Time" TitleFont="Trebuchet MS, 8.25pt" IsMarginVisible="true" IsStartedFromZero="false" Interval="Auto" IntervalAutoMode="VariableCount" IntervalType="Hours" IntervalOffset="Auto" IntervalOffsetType="Hours">
               <LabelStyle Font="Trebuchet MS, 6.25pt" Format="MM/dd/yyyy MM:mmt" Angle="90" />           
              </AxisX>
              <AxisY Title="Temperature" TitleFont="Trebuchet MS, 8.25pt">
               <LabelStyle Font="Trebuchet MS, 6.25pt" />
              </AxisY>
              <AxisY2 Title="%" TitleFont="Trebuchet MS, 8.25pt">
               <LabelStyle Font="Trebuchet MS, 6.25pt" />
              </AxisY2>
              <area3dstyle IsRightAngleAxes="False" IsClustered="False" Perspective="10" Inclination="15" Rotation="10" WallWidth="0" /> 
             </asp:ChartArea>
            </ChartAreas>
           </asp:Chart>
    

    Here is the actual data coming from SQL Server which I connect via an ObjectDataSource:

     

     

     


    The Doctor is in... "There is a fine line between Saturday night and Sunday morning."

    11/7/2010 13:00	55	23	55	5	330	NW	0.11	0.28
    11/7/2010 16:00	57	23	57	5	320	NW	0.11	0.27
    11/7/2010 19:00	48	27	48	2	320	NW	0.10	0.43
    11/7/2010 22:00	41	29	41	1	300	NW	0.10	0.62
    11/8/2010 1:00	37	29	37	0	280	W	0.08	0.72
    11/8/2010 4:00	36	29	36	1	290	W	0.08	0.75
    11/8/2010 7:00	34	29	34	2	280	W	0.08	0.82
    11/8/2010 10:00	50	30	50	5	290	W	0.08	0.46
    11/8/2010 13:00	64	31	64	6	290	W	0.07	0.29
    11/8/2010 16:00	67	31	67	7	290	W	0.07	0.26
    11/8/2010 19:00	57	35	57	4	300	NW	0.09	0.43
    11/8/2010 22:00	49	36	49	3	290	W	0.09	0.60
    
    

    I don't get it!!!  PLEASE HELP........

     

    Thanks in advance... 

    UPDATED WITH MY OWN ANSWER

    The problem with with my Format string (although I am not sure why).  I changed the Format for the DateTime to g from MM/dd/yyyy MM:hht and it worked fine...

     

    • Proposed as answer by TheDoctor30306 Sunday, November 7, 2010 8:32 PM
    Sunday, November 7, 2010 5:30 PM