开发者

Why does setting the y axis in a ms chart break the appearance of my stacked columns?

开发者 https://www.devze.com 2023-01-19 05:06 出处:网络
I\'m trying to get the y axis values displayed as in image 1, but have the data display as it does in image two (but reversed to match the axis values).

Why does setting the y axis in a ms chart break the appearance of my stacked columns?

Why does setting the y axis in a ms chart break the appearance of my stacked columns?

I'm trying to get the y axis values displayed as in image 1, but have the data display as it does in image two (but reversed to match the axis values).

Here's the code I've been working with:

 private void BindChart()
    {  
        int intSectionCount = 4;
        int day = DateTime.Now.Day;
        int month = DateTime.Now.Month;
        int year = DateTime.Now.Year;
        Random random = new Random();

        for (int pointIndex = 0; pointIndex < intSectionCount; pointIndex++)
开发者_开发知识库        {
            //Series are the number of classes per section and the points are the start times of the class?
            //these numbers stack on top of each other.
            //What if vacant time slots or grace periods alloted to time before classes start

            //determine real datetime based on excel spreadsheet data

            //each series is a class?

            //section count to be determined dynamically
            //is the number of 'pool sections' (a pool can hold mulitiple classes)


            int sec = 0;
            int min = 0;// ((int)random.Next(1, 2) == 1) ? 0 : 30;
            int hour = 4;// (int)random.Next(16, 18);


            System.DateTime baseTime = new DateTime(year, month, day, hour, min, sec);
            DateTime y = baseTime;



            Chart1.Series["Series1"].Points.AddY(y.ToOADate());

            //increment
            y = y.AddMinutes(30);

            Chart1.Series["Series2"].Points.AddY(y.ToOADate());


            //increment
            y = y.AddMinutes(30);
            Chart1.Series["Series3"].Points.AddY(y.ToOADate());


            //increment
            y = y.AddMinutes(30);
            Chart1.Series["Series4"].Points.AddY(y.ToOADate());



        }


        Chart1.ChartAreas[0].AxisY.Minimum = (new DateTime(year, month, day, 16, 00, 00)).ToOADate();
        Chart1.ChartAreas[0].AxisY.Maximum = (new DateTime(year, month, day, 21, 00, 00)).ToOADate();
        Chart1.ChartAreas[0].AxisY.IsReversed = true;
        Chart1.ChartAreas[0].AxisY.IntervalType = System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Minutes;
        Chart1.ChartAreas[0].AxisY.Interval = 30;
        Chart1.ChartAreas[0].AxisX.Enabled = System.Web.UI.DataVisualization.Charting.AxisEnabled.False;


    } 

Renders the first image, and if I comment out:

//Chart1.ChartAreas[0].AxisY.Minimum = (new DateTime(year, month, day, 16, 00, 00)).ToOADate();
//Chart1.ChartAreas[0].AxisY.Maximum = (new DateTime(year, month, day, 21, 00, 00)).ToOADate();
//Chart1.ChartAreas[0].AxisY.IsReversed = true;
//Chart1.ChartAreas[0].AxisY.IntervalType = System.Web.UI.DataVisualization.Charting.DateTimeIntervalType.Minutes;
//Chart1.ChartAreas[0].AxisY.Interval = 30;
//Chart1.ChartAreas[0].AxisX.Enabled = System.Web.UI.DataVisualization.Charting.AxisEnabled.False;

I end with a chart that looks like the 2nd image. What am I missing?

Here's the html as well:

<asp:Chart ID="Chart1" runat="server" Height="296px" Width="412px" BackColor="#D3DFF0"
    Palette="BrightPastel" BorderDashStyle="Solid" BackGradientStyle="TopBottom"
    BorderWidth="2" BorderColor="26, 59, 105">
    <Legends>
        <asp:Legend TitleFont="Microsoft Sans Serif, 8pt, style=Bold" BackColor="Transparent"
            Font="Trebuchet MS, 8.25pt, style=Bold" IsTextAutoFit="False" Enabled="False"
            Name="Default">
        </asp:Legend>
    </Legends>
    <BorderSkin SkinStyle="Emboss"></BorderSkin>
    <Series>
        <asp:Series Name="Series1" ChartType="StackedColumn" BorderColor="180, 26, 59, 105"
            Color="220, 65, 140, 240" YValueType="DateTime" IsValueShownAsLabel="True" 
            LabelFormat="{0:h:mm}">
        </asp:Series>
        <asp:Series Name="Series2" ChartType="StackedColumn" BorderColor="180, 26, 59, 105"
            Color="220, 252, 180, 65" YValueType="DateTime" IsValueShownAsLabel="True" 
            LabelFormat="{0:h:mm}">
        </asp:Series>
        <asp:Series Name="Series3" ChartType="StackedColumn" BorderColor="180, 26, 59, 105"
            Color="220, 224, 64, 10" YValueType="DateTime" IsValueShownAsLabel="True" 
            LabelFormat="{0:h:mm}">
        </asp:Series>
        <asp:Series Name="Series4" ChartType="StackedColumn" BorderColor="180, 26, 59, 105"
            Color="220, 5, 100, 146" YValueType="DateTime" IsValueShownAsLabel="True" 
            LabelFormat="{0:h:mm}">
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid"
            BackSecondaryColor="Transparent" BackColor="64, 165, 191, 228" ShadowColor="Transparent"
            BackGradientStyle="TopBottom">

            <AxisY LineColor="64, 64, 64, 64">
                <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" Format="{0:h:mm}" />
                <MajorGrid LineColor="64, 64, 64, 64" />
            </AxisY>
            <AxisX LineColor="64, 64, 64, 64">
                <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
                <MajorGrid LineColor="64, 64, 64, 64" />
            </AxisX>
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号