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

时间:2010-08-25 11:11:48

标签: c# vb.net charts data-visualization mschart

我想在C#和VB.NET中得到建议

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

alt text

  1. 如何自定义值 代码隐藏的每一列的顶部? 我没有展示21,49,19 喜欢显示21小时,49小时,19小时

  2. 如何显示这些值 其他线的顶部?如你看到的 19是在Line系列之下。

  3. 我可以设置画线 图表区域不仅仅是跨越 柱?所以,这条线将从 轴X到图表区域的末尾。

  4. 这是标记:

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

1 个答案:

答案 0 :(得分:2)

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