Hi,
I had created a dynamic chart control in VS 2010. On click of 1 chart (Piechart)other chart should load.
Here chart is the 1st chart shown.But on click of this chart event is not firing.
So I have
{
base.OnPreRender(e);
Chart chrt = new Chart();
chrt.Click += new ImageMapEventHandler(chrt_click);
}
protected void chrt_click(object sender, ImageMapEventArgs args)
{
int sliceindex = int.Parse(args.PostBackValue);
}
protected void btnViewChart_Click(object sender, EventArgs e)
{
BuildPieChart(words);
}
protected void BuildPieChart(string[] strRig)
{
try
{
Chart chrt = new Chart();
chrt.Visible = true;
//chrt.Click += new ImageMapEventHandler(chrt_click);
//chk.CheckedChanged += txtChanged;
chrt.Series.Add("consumption");
chrt.Legends.Add("TestLegend");
str="";
foreach (string value in strRig)
{
str += value + ",";
}
strRigString = str.Remove(str.Length-1);
strRemove = strRigString.Remove(strRigString.Length - 1, 1);
strRigToPass = strRemove = strRemove.Remove(0, 1);
// Response.Write(str);
DataTable dt = new DataTable();
DateTime frmDate = DateTime.Parse(txtDate.Text.Trim());
String strfrmDate = frmDate.ToString("dd/MM/YYYY");
DateTime tDate = DateTime.Parse(toDate.Text.Trim());
String strtoDate = tDate.ToString("dd/MM/YYYY");
if (strfrmDate.Trim() == strtoDate.Trim())
{
//query = string.Format("select c_department, siteid,CAST(SUM(linecost) as decimal (8,1))As Consumption from matusetrans , item where item.itemnum=matusetrans.itemnum and item.capitalized=0 and matusetrans.storeloc not like ('%VRPRJ%') and matusetrans.transdate='" + txtDate.Text.Trim() + "'and matusetrans.transdate='" + toDate.Text.Trim() + "' and matusetrans.siteid='" + ddlSite.SelectedItem.Text.Trim() + "' group by matusetrans.c_department, matusetrans.siteid, matusetrans.storeloc order by matusetrans.siteid, matusetrans.storeloc, matusetrans.c_department ");
//query = string.Format("select c_department,siteid,CAST(SUM(linecost) as decimal (18,1)) As Consumption from matusetrans,item where item.itemnum=matusetrans.itemnum and item.capitalized=0 and matusetrans.storeloc not like ('%VRPRJ%') and matusetrans.transdate='" + txtDate.Text.Trim() + "' group by matusetrans.c_department, matusetrans.siteid, matusetrans.storeloc order by matusetrans.siteid, matusetrans.storeloc, matusetrans.c_department");
//Commented on Sept 25th 2013.
// query = string.Format("select siteid,CAST(SUM(linecost) as decimal (18,1)) As Consumption from matusetrans,item where item.itemnum=matusetrans.itemnum and item.capitalized=0 and matusetrans.storeloc not like ('%VRPRJ%') and matusetrans.transdate='" + txtDate.Text.Trim() + "' group by matusetrans.c_department, matusetrans.siteid, matusetrans.storeloc order by matusetrans.siteid, matusetrans.storeloc, matusetrans.c_department");
query = string.Format("select siteid,CAST(SUM(linecost) as decimal (18,1)) As Consumption, matusetrans.currencycode from matusetrans , item where item.itemnum=matusetrans.itemnum and matusetrans.siteid IN ('" + strRigToPass.Trim() + "') and item.capitalized=0 and matusetrans.storeloc not like ('%VRPRJ%') and matusetrans.transdate='" + txtDate.Text.Trim() + "' group by matusetrans.siteid, matusetrans.currencycode");
}
else
{
//query = string.Format("select c_department,siteid,CAST(SUM(linecost) as decimal (18,1)) As Consumption from matusetrans,item where item.itemnum=matusetrans.itemnum and item.capitalized=0 and matusetrans.storeloc not like ('%VRPRJ%') and matusetrans.transdate>='" + txtDate.Text.Trim() + "' and matusetrans.transdate<='" + toDate.Text.Trim() + "' group by matusetrans.c_department, matusetrans.siteid, matusetrans.storeloc order by matusetrans.siteid, matusetrans.storeloc, matusetrans.c_department");
//Commented on Sept 25th 2013.
// query = string.Format("select siteid,CAST(SUM(linecost) as decimal (18,1)) As Consumption from matusetrans,item where item.itemnum=matusetrans.itemnum and item.capitalized=0 and matusetrans.storeloc not like ('%VRPRJ%') and matusetrans.transdate>='" + txtDate.Text.Trim() + "' and matusetrans.transdate<='" + toDate.Text.Trim() + "' group by matusetrans.c_department, matusetrans.siteid, matusetrans.storeloc order by matusetrans.siteid, matusetrans.storeloc, matusetrans.c_department");
query = string.Format("select siteid,CAST(SUM(linecost) as decimal (18,1)) As Consumption, matusetrans.currencycode from matusetrans, item where item.itemnum=matusetrans.itemnum and item.capitalized=0 and matusetrans.siteid IN ('" + strRigToPass.Trim() + "') and matusetrans.storeloc not like ('%VRPRJ%') and matusetrans.transdate>='" + txtDate.Text.Trim() + "' and matusetrans.transdate<='" + toDate.Text.Trim() + "' group by matusetrans.siteid, matusetrans.currencycode ");
}
// chrt.DataSource = sqlObj.GetTable(query);
dt = sqlObj.GetTable(query);
if (dt.Rows.Count > 0)
{
lblMessage.Text = "Daily Consumption of Rig" + " " + "from" + " " + txtDate.Text.Trim() + " " + "to" + " " + toDate.Text.Trim();
lblMessage.Visible = true;
chrt.DataSource = sqlObj.GetTable(query);
//chrt.Series["consumption"].XValueMember = "c_department";
chrt.Series["consumption"].XValueMember = "siteid";
chrt.Series["consumption"].YValueMembers = "Consumption";
chrt.Legends["TestLegend"].Enabled = true;
chrt.Legends["TestLegend"].Alignment = StringAlignment.Far;
chrt.Legends["TestLegend"].Docking = Docking.Bottom;
chrt.ChartAreas.Add("TestArea");
chrt.Series["consumption"].ChartArea = "TestArea";
chrt.ChartAreas["TestArea"].Area3DStyle.Enable3D = true;
chrt.ChartAreas["TestArea"].AxisY.TitleAlignment = StringAlignment.Center;
chrt.ChartAreas["TestArea"].AxisX.LabelStyle.Angle = -90;
chrt.ChartAreas["TestArea"].AxisY.LabelStyle.Font = new Font("Arial", 9, GraphicsUnit.Pixel);
chrt.ChartAreas["TestArea"].AxisX.LabelStyle.ForeColor = Color.Red;
chrt.ChartAreas["TestArea"].AxisY.LabelStyle.ForeColor = Color.DarkBlue;
chrt.ChartAreas["TestArea"].AxisX.TitleAlignment = StringAlignment.Near;
chrt.ChartAreas["TestArea"].AxisX.TextOrientation = TextOrientation.Horizontal;
chrt.Series["consumption"].Color = System.Drawing.Color.MediumSeaGreen;
//chrt.Series["consumption"].BorderColor = System.Drawing.Color.Yellow;
chrt.Series["consumption"].MarkerColor = System.Drawing.Color.Firebrick;
chrt.Series["consumption"].IsValueShownAsLabel = true;
chrt.Series["consumption"].ChartType = SeriesChartType.Pie;
//chrt.ChartAreas["TestArea"].AxisX.Title = "Department";
chrt.ChartAreas["TestArea"].AxisX.Title = "Rig";
// chrt.ChartAreas["TestArea"].AxisY.Title = "Consumption ins Rs";
if (dt.Rows[0]["currencycode"].ToString().Trim()=="INR")
{
chrt.ChartAreas["TestArea"].AxisY.Title = "Consumption in Rs";
}
else if (dt.Rows[0]["currencycode"].ToString().Trim()=="$")
{
chrt.ChartAreas["TestArea"].AxisY.Title = "Consumption in $";
}
chrt.DataBind();
this.Controls.Add(chrt);
//chrt.Controdd(pnlScattered);
// chrt.Series["consumption"].ToolTip = "Rig= #VALXnConsumption= Rs#VALY";
if (dt.Rows[0]["currencycode"].ToString().Trim()=="INR")
{
chrt.Series["consumption"].ToolTip = "Rig= #VALXnConsumption= Rs #VALY";
}
else if (dt.Rows[0]["currencycode"].ToString().Trim()=="$")
{
chrt.Series["consumption"].ToolTip = "Rig= #VALXnConsumption= $ #VALY";
}
}
else
{
lblValidate.Visible = true;
lblValidate.Text = "No Records Are Found";
}
}
catch (Exception Ex)
{
lblGreen.Visible = true;
lblValidate.Visible = true;
lblValidate.Text = Ex.Message;
lblGreen.Text = "";
}
}
But this is not called on chart click . Any idea?