locked
ASP Chart issue RRS feed

  • Question

  • User-953209254 posted

    So I have a simple chart with X axes showing dayofweek starting Monday and Y axes showing total amount of sales. However, for some reason X axes always adding an extra day even though I am not assigning any values to it. I've tried adding IsMarginVisible but that screws up things even worse. Below is my code for Thursday. Thanks for any input.

    Dim x As DateTime() = New DateTime(3) {}
    Dim y As Decimal() = New Decimal(3) {}
    
    x(0) = Now.AddDays(-3)
    y(0) = ds.Tables(0).Rows(0).Item(0)
    x(1) = Now.AddDays(-2)
    y(1) = ds.Tables(1).Rows(0).Item(0)
    x(2) = Now.AddDays(-1)
    y(2) = ds.Tables(2).Rows(0).Item(0)
    x(3) = Now
    y(3) = ds.Tables(3).Rows(0).Item(0)
    
    Chart1.Series(0).Points.DataBindXY(x, y)
    Chart1.Series(0).XValueType = ChartValueType.DateTime
    Chart1.Series(0).YValueType = ChartValueType.Double
    Chart1.Series(0).ChartType = SeriesChartType.Column
    Chart1.Series(0).Name = "Sales (amt)"
    Chart1.Series(0).IsValueShownAsLabel = True
    Chart1.Series(0).Label = "$" & "#VALY"
    
    Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "C"
    Chart1.ChartAreas(0).AxisY.Interval = 100
    Chart1.ChartAreas(0).AxisY.IntervalType = DateTimeIntervalType.Number
    Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "dddd"
    Chart1.ChartAreas(0).AxisX.Interval = 1
    Chart1.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Days
    Chart1.ChartAreas(0).AxisX.MajorGrid.Enabled = False
    Chart1.ChartAreas(0).AxisY.MajorGrid.Enabled = False

    Thursday, May 5, 2016 3:02 PM

Answers

  • User1559292362 posted

    Hi faremax,

    for some reason X axes always adding an extra day even though I am not assigning any values to it

    I create a demo and reproduce you issue on my side, you need to modify the value of Chart1.ChartAreas(0).AxisX.IntervalType to DateTimeIntervalType.Auto. then setting the value IsMarginVisible to false, like this:

    Dim x As DateTime() = New DateTime(3) {}
            Dim y As Decimal() = New Decimal(3) {}
    
            x(0) = Now.AddDays(-3)
            y(0) = ds.Tables(0).Rows(0).Item(0)
            x(1) = Now.AddDays(-2)
            y(1) = ds.Tables(1).Rows(0).Item(0)
            x(2) = Now.AddDays(-1)
            y(2) = ds.Tables(2).Rows(0).Item(0)
            x(3) = Now
            y(3) = ds.Tables(3).Rows(0).Item(0)
    
            Chart1.Series(0).Points.DataBindXY(x, y)
            Chart1.Series(0).XValueType = ChartValueType.DateTime
            Chart1.Series(0).YValueType = ChartValueType.Double
            Chart1.Series(0).ChartType = SeriesChartType.Column
            Chart1.Series(0).Name = "Sales (amt)"
            Chart1.Series(0).IsValueShownAsLabel = True
            Chart1.Series(0).Label = "$" & "#VALY"
    
            Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "C"
            Chart1.ChartAreas(0).AxisY.Interval = 100
            Chart1.ChartAreas(0).AxisY.IntervalType = DateTimeIntervalType.Number
            Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "dddd"
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Auto
            Chart1.ChartAreas(0).AxisX.IsMarginVisible = False
            Chart1.ChartAreas(0).AxisX.MajorGrid.Enabled = True
            Chart1.ChartAreas(0).AxisY.MajorGrid.Enabled = True

    Best regards,

    Cole Wu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 7, 2016 6:47 AM