Issue in Different Graph Color in ASP.NET
I want any different color for each bar such as Inseminated, Repeated, Fresher, Open, Insemination Free.
how to get solution pls
I wrote the following code
<div class="col-sm-12">
<div class="table-responsive">
<asp:GridView ID="GridView1" runat="server" AllowPaging="false" RowStyle-Wrap="false"
HeaderStyle-Wrap="false" Class="table table-striped table-bordered table-hover">
</asp:GridView>
<cc1:BarChart ID="BarChart1" runat="server" ChartHeight="300" ChartWidth="450" ChartType="Column"
ChartTitleColor="#0E426C" CategoryAxisLineColor="#D08AD9" ValueAxisLineColor="#D08AD9"
BaseLineColor="#A156AB">
</cc1:BarChart>
</div>
</div>
protected void BindGrid()
{
string query = string.Format(@"SELECT Head,Count
INTO #Temp
FROM
(
SELECT 'Inseminated:' as 'Head' ,count(t1.TagID) 'Count' FROM tblBreading t1 LEFT JOIN tblPRegTest t2 ON t1.TagID = t2.TagID and t1.I_Date = t2.I_Date WHERE t2.TagID IS NULL
union all
SELECT 'Repeated:' as 'Head' ,count(t1.TagID) 'count' FROM tblPregTest t1 LEFT JOIN tblBreading t2 ON t1.TagID = t2.TagID WHERE P_Result='Negative' and t1.C_Date > t2.I_Date
union all
SELECT 'Fresher:' as 'Head', count(TagID) 'count' from tblCalving where DATEDIFF(day, C_Date, CONVERT(CHAR(50), GETDATE(), 23)) < 45
union all
SELECT 'Open:' as 'Head', count(t1.TagID) 'count' FROM tblCalving t1 LEFT JOIN tblBreading t2 ON t1.TagID = t2.TagID WHERE t1.C_Date > t2.I_Date and DATEDIFF(day, t1.C_Date, CONVERT(CHAR(50), GETDATE(), 23)) > 45
union all
SELECT 'Insemination Free:' as 'Head', count(t1.TagID) 'count' FROM tblAnimal t1 LEFT JOIN tblBreading t2 ON t1.TagID = t2.TagID WHERE t2.TagID IS NULL
)t
SELECT *,ROUND(CAST((CAST(Count AS DECIMAL)/(SELECT SUM(Count) FROM #Temp))*100 AS Float),2) 'Percentage'
FROM #Temp
DROP TABLE #Temp");
DataTable dt = GetData(query);
string[] x = new string[dt.Rows.Count];
decimal[] y = new decimal[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToDecimal(dt.Rows[i][1].ToString()); //y[i] = Convert.ToInt32(dt.Rows[i][1]); //.Replace("%", "").Trim()
}
BarChart1.Series.Add(new AjaxControlToolkit.BarChartSeries { Data = y });
BarChart1.CategoriesAxis = string.Join(",", x);
BarChart1.ChartTitle = string.Format("Breading Report");
if (x.Length > 3)
{
BarChart1.ChartWidth = (x.Length * 150).ToString();
}
}