Hi eshant.kapoor...,
In the ChartArea add AxisY and inside the AxisY add two StripLine inside the StripLines.
Then set the StripLine IntervalOffset value from code behind.
Refer below sample.
HTML
<asp:Chart ID="Chart1" runat="server" Height="300px" Width="500px">
<Titles>
<asp:Title ShadowOffset="3" Name="Items" />
</Titles>
<Series>
<asp:Series Name="Default"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BorderWidth="0">
<AxisY>
<StripLines>
<asp:StripLine BorderColor="Red" BorderWidth="4" BackColor="Red" />
<asp:StripLine BorderColor="Orange" BorderWidth="3" BackColor="Orange" />
</StripLines>
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
Namepsaces
C#
using System.Data;
using System.Web.UI.DataVisualization.Charting;
VB.Net
Imports System.Data
Imports System.Web.UI.DataVisualization.Charting
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = this.GetData();
double min = dt.AsEnumerable().Select(x => x.Field<int>("MinDays")).Max();
double max = dt.AsEnumerable().Select(x => x.Field<int>("MaxDays")).Max();
Chart1.DataSource = dt;
Chart1.Series[0].ChartType = SeriesChartType.Column;
Chart1.Series[0].XValueMember = "Item";
Chart1.Series[0].YValueMembers = "CurrentStock";
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
// Draw Min Line.
Chart1.ChartAreas["ChartArea1"].AxisY.StripLines[0].IntervalOffset = min;
// Draw Max Line.
Chart1.ChartAreas["ChartArea1"].AxisY.StripLines[1].IntervalOffset = max;
Chart1.DataBind();
}
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Item", typeof(string));
dt.Columns.Add("CurrentStock", typeof(int));
dt.Columns.Add("MinDays", typeof(int));
dt.Columns.Add("MaxDays", typeof(int));
dt.Rows.Add("A", 2400, 1500, 5000);
dt.Rows.Add("B", 1200, 1500, 5000);
dt.Rows.Add("C", 6000, 1500, 5000);
dt.Rows.Add("D", 576, 1500, 5000);
return dt;
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = GetData()
Dim min As Double = dt.AsEnumerable().Select(Function(x) x.Field(Of Integer)("MinDays")).Max()
Dim max As Double = dt.AsEnumerable().Select(Function(x) x.Field(Of Integer)("MaxDays")).Max()
Chart1.DataSource = dt
Chart1.Series(0).ChartType = SeriesChartType.Column
Chart1.Series(0).XValueMember = "Item"
Chart1.Series(0).YValueMembers = "CurrentStock"
Chart1.ChartAreas("ChartArea1").AxisX.MajorGrid.Enabled = False
Chart1.ChartAreas("ChartArea1").AxisY.MajorGrid.Enabled = False
' Draw Min Line.
Chart1.ChartAreas("ChartArea1").AxisY.StripLines(0).IntervalOffset = min
' Draw Max Line.
Chart1.ChartAreas("ChartArea1").AxisY.StripLines(1).IntervalOffset = max
Chart1.DataBind()
End If
End Sub
Private Function GetData() As DataTable
Dim dt As DataTable = New DataTable()
dt.Columns.Add("Item", GetType(String))
dt.Columns.Add("CurrentStock", GetType(Integer))
dt.Columns.Add("MinDays", GetType(Integer))
dt.Columns.Add("MaxDays", GetType(Integer))
dt.Rows.Add("A", 2400, 1500, 5000)
dt.Rows.Add("B", 1200, 1500, 5000)
dt.Rows.Add("C", 6000, 1500, 5000)
dt.Rows.Add("D", 576, 1500, 5000)
Return dt
End Function
Screenshot