MS Chart 自定义值标签并在图表区域绘制线条系列

发布于 2024-09-15 18:29:38 字数 3119 浏览 4 评论 0原文

我想获得 C# 和 VB.NET 的建议

我创建了如下图所示的图表:

alt text

  1. 如何自定义 来自代码隐藏的每列顶部? 我不会显示 21、49、19 喜欢显示 21 小时、49 小时、19 小时

  2. 如何在 其他行的顶部?如你看到的 19 位于 Line 系列下方。

  3. 我可以设置在 图表区域不只是跨越 柱子?所以,该行将从 X 轴到图表区域的末尾。

这是标记:

 <asp:chart id="Chart1" runat="server" Height="296px" Width="500" ImageLocation="~/TempChartFiles/ChartPic_#SEQ(300,3)" Palette="BrightPastel" imagetype="Png" BorderDashStyle="Solid" BackSecondaryColor="White" BackGradientStyle="TopBottom" BorderWidth="2" backcolor="#D3DFF0" BorderColor="26, 59, 105">
                    <legends>
                        <asp:Legend IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"></asp:Legend>
                    </legends>
                    <borderskin skinstyle="Emboss"></borderskin>
                    <series>
                        <asp:Series Name="Month" BorderColor="180, 26, 59, 105" IsValueShownAsLabel="true">
                        </asp:Series>
                    </series>
                    <chartareas>
                        <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" BackSecondaryColor="White" BackColor="64, 165, 191, 228" ShadowColor="Transparent" BackGradientStyle="TopBottom">
                            <area3dstyle Rotation="10" perspective="10" Inclination="15" IsRightAngleAxes="False" wallwidth="0" IsClustered="False"></area3dstyle>
                            <axisy linecolor="64, 64, 64, 64">
                                <labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />
                                <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>

这是隐藏代码:

Chart1.ChartAreas("ChartArea1").AxisX.Interval = 1

    ' Create new data series and set its visual attributes
    Dim series As New Series("Minimum Hour")

    series.ChartType = SeriesChartType.Line
    series.BorderWidth = 2
    series.ShadowOffset = 1
    series.AxisLabel = 0


    Dim monthyHour = 22
    series.Name = "Min. Hour : " & monthyHour

    Dim xValue() As String = {"Jun", "Jul", "Aug"}
    Dim yValue() As Integer = {21, 49, 19}

    'add value for Line series
    For i = 0 To xValue.Length - 1 Step 1

         series.Points.AddY(monthyHour)

    Next

    Chart1.Series(0).Points.DataBindXY(xValue, yValue)

    ' Add series into the chart's series collection
    Chart1.Series.Add(Series)

I'd like to get suggestion in both C# and VB.NET

I created Chart like the following image:

alt text

  1. How can I customize the value on the
    top of each column from code-behind?
    Instead of showing 21, 49, 19 I'd
    like to show 21 hr, 49 hr, 19 hr

  2. How can I show the those values on
    top of other lines? As you can see
    19 is below the Line series.

  3. Can I set draw the line across the
    Chart Area not just across the
    column? So, the line will start from
    Axis X to end of the Chart Area.

Here's the mark-up:

 <asp:chart id="Chart1" runat="server" Height="296px" Width="500" ImageLocation="~/TempChartFiles/ChartPic_#SEQ(300,3)" Palette="BrightPastel" imagetype="Png" BorderDashStyle="Solid" BackSecondaryColor="White" BackGradientStyle="TopBottom" BorderWidth="2" backcolor="#D3DFF0" BorderColor="26, 59, 105">
                    <legends>
                        <asp:Legend IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"></asp:Legend>
                    </legends>
                    <borderskin skinstyle="Emboss"></borderskin>
                    <series>
                        <asp:Series Name="Month" BorderColor="180, 26, 59, 105" IsValueShownAsLabel="true">
                        </asp:Series>
                    </series>
                    <chartareas>
                        <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" BackSecondaryColor="White" BackColor="64, 165, 191, 228" ShadowColor="Transparent" BackGradientStyle="TopBottom">
                            <area3dstyle Rotation="10" perspective="10" Inclination="15" IsRightAngleAxes="False" wallwidth="0" IsClustered="False"></area3dstyle>
                            <axisy linecolor="64, 64, 64, 64">
                                <labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />
                                <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>

Here's the code-behind:

Chart1.ChartAreas("ChartArea1").AxisX.Interval = 1

    ' Create new data series and set its visual attributes
    Dim series As New Series("Minimum Hour")

    series.ChartType = SeriesChartType.Line
    series.BorderWidth = 2
    series.ShadowOffset = 1
    series.AxisLabel = 0


    Dim monthyHour = 22
    series.Name = "Min. Hour : " & monthyHour

    Dim xValue() As String = {"Jun", "Jul", "Aug"}
    Dim yValue() As Integer = {21, 49, 19}

    'add value for Line series
    For i = 0 To xValue.Length - 1 Step 1

         series.Points.AddY(monthyHour)

    Next

    Chart1.Series(0).Points.DataBindXY(xValue, yValue)

    ' Add series into the chart's series collection
    Chart1.Series.Add(Series)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤城病女 2024-09-22 18:29:38

要从后面的代码添加它,您需要设置 Chart1.Series(0).Label=monthyHour +"Hrs"

To add it from code behind you need to set Chart1.Series(0).Label=monthyHour +"Hrs"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文