1

替代文字

替代文字

我试图让 y 轴值显示为图像 1,但数据显示与图像 2 中的一样(但反转以匹配轴值)。

这是我一直在使用的代码:

 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;


    } 

渲染第一张图片,如果我注释掉:

//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;

我以一个看起来像第二张图片的图表结束。我错过了什么?

这里的html也是:

<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>
4

0 回答 0