MS Chart 自定义值标签并在图表区域绘制线条系列
我想获得 C# 和 VB.NET 的建议
我创建了如下图所示的图表:
如何自定义 来自代码隐藏的每列顶部? 我不会显示 21、49、19 喜欢显示 21 小时、49 小时、19 小时
如何在 其他行的顶部?如你看到的 19 位于 Line 系列下方。
我可以设置在 图表区域不只是跨越 柱子?所以,该行将从 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:
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 hrHow can I show the those values on
top of other lines? As you can see
19 is below the Line series.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从后面的代码添加它,您需要设置 Chart1.Series(0).Label=monthyHour +"Hrs"
To add it from code behind you need to set Chart1.Series(0).Label=monthyHour +"Hrs"