簡體   English   中英

如何使用ms圖表控件將y軸值增加15分鍾

[英]how to increment y axis values by 15 minutes using ms chart controls

我正在使用MS圖表控件stackcolumn圖表類型,我希望y軸標簽在下午4點到晚上9點之間間隔增加15分鍾。 我附上了圖表的圖像,並附上了生成圖像的示例代碼。

替代文字

<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="Time" IsValueShownAsLabel="True" 
            LabelFormat="{0:HH:mm:ss}">
        </asp:Series>
        <asp:Series Name="Series2" ChartType="StackedColumn" BorderColor="180, 26, 59, 105"
            Color="220, 252, 180, 65" YValueType="Time" IsValueShownAsLabel="True" 
            LabelFormat="{0:HH:mm:ss}">
        </asp:Series>
        <asp:Series Name="Series3" ChartType="StackedColumn" BorderColor="180, 26, 59, 105"
            Color="220, 224, 64, 10" YValueType="Time" IsValueShownAsLabel="True" 
            LabelFormat="{0:HH:mm:ss}">
        </asp:Series>
        <asp:Series Name="Series4" ChartType="StackedColumn" BorderColor="180, 26, 59, 105"
            Color="220, 5, 100, 146" YValueType="Time" IsValueShownAsLabel="True" 
            LabelFormat="{0:HH:mm:ss}">
        </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">
            <Area3DStyle Rotation="10" Inclination="15" WallWidth="0" />
            <Position Y="3" Height="92" Width="92" X="2"></Position>
            <AxisY LineColor="64, 64, 64, 64" LabelAutoFitMaxFontSize="8">
                <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
                <MajorGrid LineColor="64, 64, 64, 64" />
            </AxisY>
            <AxisX LineColor="64, 64, 64, 64" LabelAutoFitMaxFontSize="8">
                <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
                <MajorGrid LineColor="64, 64, 64, 64" />
            </AxisX>
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>

在后面的代碼中我綁定了一些測試數據:

 private void BindChart()
    {
        Random random = new Random();

        //each series is a class?

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

        int intSectionCount = 4;

        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


            int sec = 0;
            int min = ((int)random.Next(1, 2) == 1) ? 0 : 30;
            int hour = (int)random.Next(16, 18);
            int day = DateTime.Now.Day;
            int month = DateTime.Now.Month;
            int year = DateTime.Now.Year;

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


            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.Series["Series1"].Points.AddY(Math.Round((double)random.Next(45, 95),0));
            //Chart1.Series["Series2"].Points.AddY(Math.Round((double)random.Next(5, 75),0));
            //Chart1.Series["Series3"].Points.AddY(Math.Round((double)random.Next(5, 95),0));
            //Chart1.Series["Series4"].Points.AddY(Math.Round((double)random.Next(35, 95),0));
        }           
    }

 Chart1.ChartAreas[0].AxisY.Minimum = (new DateTime(2010, 10, 31, 16, 00, 00)).ToOADate();
        Chart1.ChartAreas[0].AxisY.Maximum = (new DateTime(2010, 10, 31, 21, 00, 00)).ToOADate();
        Chart1.ChartAreas[0].AxisY.IsReversed = true;

弄清楚了:

Chart1.ChartAreas[0].AxisY.Minimum = (new DateTime(2010, 10, 31, 16, 00, 00)).ToOADate();
Chart1.ChartAreas[0].AxisY.Maximum = (new DateTime(2010, 10, 31, 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 = 15;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM