Reputation: 166
I want to add a spline graphic and a points graphic on the same asp.net chart. Can somebody show an explicite example of how you do that?
Thank you.
Upvotes: 0
Views: 301
Reputation: 604
Would be nice to know if you want a C# or a Visual Basic example. I've got a Visual Basic one for you. (You could convert it to C# with an online converter). I hope this helps you.
.aspx file:
<form id="form1" runat="server">
<div>
<asp:Chart ID="Chart1" runat="server">
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</form>
.vb file:
Imports System.Web.UI.DataVisualization.Charting
Imports System.Drawing
Public Class ChartExample
Inherits System.Web.UI.Page
Private Sub Page_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Add the title
Chart1.Titles.Add("Title1")
' Set the text of the title
Chart1.Titles("Title1").Text = "Chart Area 1 Title"
' Dock the title to a ChartArea
Chart1.Titles("Title1").DockedToChartArea = "ChartArea1"
' Creating the series
Dim series1 As New Series("Series1")
Dim series2 As New Series("Series2")
' Setting the Chart Type
series1.ChartType = SeriesChartType.Spline
series2.ChartType = SeriesChartType.Point
' Adding some points
series1.Points.AddXY(0, 10)
series1.Points.AddXY(5, 16)
series1.Points.AddXY(10, 9)
series1.Points.AddXY(15, 32)
series1.Points.AddXY(20, 21)
series2.Points.AddXY(0, 5)
series2.Points.AddXY(5, 12)
series2.Points.AddXY(10, 18)
series2.Points.AddXY(15, 11)
series2.Points.AddXY(20, 25)
' Add the series to the chart
Chart1.Series.Add(series1)
Chart1.Series.Add(series2)
' Set the chart's height and width
Chart1.Width = 600
Chart1.Height = 600
' Setting the X Axis
Chart1.ChartAreas("ChartArea1").AxisX.IsMarginVisible = True
Chart1.ChartAreas("ChartArea1").AxisX.Interval = 1
Chart1.ChartAreas("ChartArea1").AxisX.Maximum = [Double].NaN
Chart1.ChartAreas("ChartArea1").AxisX.Title = "x"
Chart1.ChartAreas("ChartArea1").AxisX.TitleFont = New Font("Sans Serif", 10, FontStyle.Bold)
' Setting the Y Axis
Chart1.ChartAreas("ChartArea1").AxisY.Interval = 2
Chart1.ChartAreas("ChartArea1").AxisY.Maximum = [Double].NaN
Chart1.ChartAreas("ChartArea1").AxisY.Title = "y"
Chart1.ChartAreas("ChartArea1").AxisY.TitleFont = New Font("Sans Serif", 10, FontStyle.Bold)
End Sub
End Class
Upvotes: 2