Tushar Goel

Tushar Goel

  • NA
  • 26
  • 0

how to create two chart in same chart area.

Feb 13 2011 9:14 AM

Hi,
 
I want to create 2 chart between (severity and target ) and 2nd between (severity and actual) in same samechart. I am able to create between severity and actual but unable for other. I am using follwing code for this. Can any suggest what changes needs to be done to display both charts into same area.
 
void SetChartAreaFeatures(Chart tmpChart, String tmpArea)
{
tmpChart.ChartAreas[tmpArea].BorderDashStyle =
ChartDashStyle.Solid;
tmpChart.ChartAreas[tmpArea].BorderWidth = 2;
tmpChart.BorderSkin.SkinStyle =
BorderSkinStyle.Emboss;
tmpChart.BorderlineColor = System.Drawing.
Color.FromArgb(26, 59, 105);
tmpChart.BorderlineWidth = 2;
tmpChart.BackColor =
Color.AliceBlue;
tmpChart.ChartAreas[tmpArea].BackColor =
Color.White;
tmpChart.ChartAreas[tmpArea].BackHatchStyle =
ChartHatchStyle.None;
tmpChart.ChartAreas[tmpArea].BackGradientStyle =
GradientStyle.None;
tmpChart.ChartAreas[tmpArea].BorderColor =
Color.Black;
tmpChart.ChartAreas[tmpArea].BorderDashStyle =
ChartDashStyle.Solid;
tmpChart.ChartAreas[tmpArea].BorderWidth = 1;
}
 
 
protected void Button1_Click(object sender, EventArgs e)
{
DateTime FromDate = Convert.ToDateTime(TextBox1.Text);
DateTime ToDate = Convert.ToDateTime(TextBox2.Text);
 

Chart1.Legends.Clear();
Chart1.Series.Clear();
Chart1.ChartAreas.Clear();
 
StringBuilder sb = new StringBuilder();
sb.Append(
"select re.Severity ,(select tv.Target from tbl_TargetValue tv where tv.Severity=re.Severity) as 'Target' ,Present=sum(re.SLAMet)*100/(sum(re.SLAMet)+sum(re.SLANotMet)) from tbl_Report re , tbl_TargetValue tv where tv.Severity=re.Severity and re.EventStartTime between '" + FromDate + "' and '" + ToDate + "' group by re.Severity");
using (SqlDataAdapter sda = new SqlDataAdapter(sb.ToString(), System.Configuration.ConfigurationManager.ConnectionStrings[""].ToString()))
{
 
DataSet ds = new DataSet();
sda.Fill(ds);
 
if (ds.Tables[0].Rows.Count > 0)
{
Chart1.ChartAreas.Add(
"re.Severity");
SetChartAreaFeatures(Chart1,
"re.Severity");
Chart1.ChartAreas[0].AxisX.Title =
"Severity";
Chart1.ChartAreas[0].AxisY.Title =
"Percentage";
// Chart1.ChartAreas[1].AxisX.Title = "Severity";
Chart1.ChartAreas[0].AxisX.TitleFont =
new System.Drawing.Font("Verdana", 10, System.Drawing.FontStyle.Bold);
Chart1.ChartAreas[0].AxisX.Minimum = 0;
Chart1.ChartAreas[0].AxisX.Interval = 1;
Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled =
false;
Chart1.ChartAreas[0].AxisY.TitleFont =
new System.Drawing.Font("Verdana", 10, System.Drawing.FontStyle.Bold);
Chart1.ChartAreas[0].AxisY2.LineColor =
Color.Black;
Chart1.Series.Add(
"re.Severity");
Chart1.Series[0].IsVisibleInLegend =
false;
Chart1.Series[0].Palette =
ChartColorPalette.Bright;
Chart1.Series[0].ChartType =
SeriesChartType.Column;
Chart1.Series[0][
"DrawingStyle"] = "Emboss";
Chart1.Series[0].Points.DataBindXY(ds.Tables[0].DefaultView,
"Severity", ds.Tables[0].DefaultView, "Present");
//Chart1.Series[1].Points.DataBindXY(ds.Tables[0].DefaultView, "Severity", ds.Tables[0].DefaultView, "Actual");
Chart1.Legends.Add(
"re.Severity");
List<string> colorList = new List<string>();
colorList.Add(
"Red");
colorList.Add(
"Green");
colorList.Add(
"Yellow");
colorList.Add(
"Purple");
colorList.Add(
"Orange");
colorList.Add(
"Blue");
colorList.Add(
"Brown");
colorList.Add(
"Teal");
colorList.Add(
"SkyBlue");
colorList.Add(
"Flusia");
colorList.Add(
"Pink");
for (int i = 0; i < Chart1.Series[0].Points.Count; i++)
{
Chart1.Series[0].Points[i].Color =
Color.FromName(colorList[i]);
// Chart1.Series[i+0].Points[i].Color = Color.FromName(colorList[i]);
}
 
Regards
Tushar Goel

Answers (8)