hi I am trying to represent the two graphs(pie chart and bar chart) on one form using mschart controls….the data is coming from database ….
I am using single chart(kpichart) control to represent the two graphs ….
for that i ahve wrrittent teh below code
In this code i have defined two different areas to defining two graphs…..
public void KpiMembers_MouseClick(object sender, MouseEventArgs e)
{
Series statusseries;
Series liveserries = null;
string area;
Title title;
try
{
var pos = e.Location;
var results = KpiMembersTotalchart.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
foreach (var result in results)
{
if (result.ChartElementType == ChartElementType.DataPoint)
{
if (result.Series.Points[result.PointIndex].AxisLabel == "Live")
{
DataTable Livemembers = null;
Livemembers = KpiData.livemembersmembershipstatus();
DataTable membersalltotals = null;
membersalltotals = kpimembtotals.membershipTotals(dtpStartDate.Value, dtpenddate.Value);
KpiMembersTotalchart.ChartAreas.Clear();
KpiMembersTotalchart.Titles.Clear();
KpiMembersTotalchart.Series.Clear();
area = "newchart";
KpiMembersTotalchart.ChartAreas.Add(area);
liveserries = KpiMembersTotalchart.Series.Add(area);
liveserries.ChartArea = area;
title = KpiMembersTotalchart.Titles.Add("Memberstotalspoints");
title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
title.Alignment = ContentAlignment.TopLeft;
title.DockedToChartArea = area;
KpiMembersTotalchart.Titles.Add("").DockedToChartArea = area;
area = "subchart";
KpiMembersTotalchart.ChartAreas.Add(area);
statusseries = KpiMembersTotalchart.Series.Add(area);
statusseries.ChartArea = area;
title = KpiMembersTotalchart.Titles.Add("Live Status members by status");
title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
title.Alignment = ContentAlignment.TopLeft;
title.DockedToChartArea = area;
KpiMembersTotalchart.Titles.Add("").DockedToChartArea = area;
foreach (Title chartTitle in KpiMembersTotalchart.Titles)
{
chartTitle.IsDockedInsideChartArea = false;
}
foreach (ChartArea chartArea in KpiMembersTotalchart.ChartAreas)
{
chartArea.Area3DStyle.Enable3D = true;
chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;
}
if (area == "subchart")
{
foreach (Series charttypes in KpiMembersTotalchart.Series)
{
charttypes.ChartType = SeriesChartType.Pie;
charttypes["PielabelStyle"] = "Outside";
charttypes["DoughnutRadius"] = "30";
charttypes["PieDrawingStyle"] = "SoftEdge";
charttypes.BackGradientStyle = GradientStyle.DiagonalLeft;
}
}
if (area == "newchart")
{
foreach (Series chartareas in KpiMembersTotalchart.Series)
{
chartareas.ChartType = SeriesChartType.StackedColumn;
chartareas["ColumnDrawingStyle"] = "SoftEdge";
chartareas["LabelStyle"] = "Top";
chartareas.IsValueShownAsLabel = true;
chartareas.BackGradientStyle = GradientStyle.DiagonalLeft;
}
}
foreach (Legend legend in KpiMembersTotalchart.Legends)
{
legend.Enabled = false;
}
if (membersalltotals == null)
{
statusseries.Points.Clear();
statusseries.Points.AddXY("no status", 0);
}
if(Livemembers == null)
{
liveserries.Points.Clear();
liveserries.Points.AddXY("no membershipe", 0);
}
KpiMembersTotalchart.Series["newchart"].Points.DataBindXY(membersalltotals.Rows, "Status", membersalltotals.Rows, "Value");
KpiMembersTotalchart.Series["subchart"].Points.DataBindXY(Livemembers.Rows, "mshipname", Livemembers.Rows, "count");
if (area == "subchart")
{
foreach (Series charttypes in KpiMembersTotalchart.Series)
{
foreach (DataPoint point in charttypes.Points)
{
switch (point.AxisLabel)
{
case "New": point.Color = Color.Cyan; break;
case "Live": point.Color = Color.Green; break;
case "Defaulter": point.Color = Color.Red; break;
case "Cancelled": point.Color = Color.Orange; break;
case "Completed": point.Color = Color.Blue; break;
case "Frozen": point.Color = Color.Violet; break;
}
point.Label = string.Format("{0:0} - {1}", point.YValues[0], point.AxisLabel);
}
}
}
if (area == "newchart")
{
foreach (Series chartareas in KpiMembersTotalchart.Series)
{
foreach (DataPoint point in chartareas.Points)
{
switch (point.AxisLabel)
{
case "Silver membership": point.Color = Color.Green; break;
case "Gold Membership": point.Color = Color.Blue; break;
//case "Refused": point.Color = Color.Red; break;
case "Weekend Peak": point.Color = Color.Cyan; break;
case "prspect": point.Color = Color.Indigo; break;
}
point.Label = string.Format("{0:0}", point.YValues[0]);
}
}
}
}
}
}
}
catch { }
}
My problem is i am trying to showing the two different charts (one is pie chart and another one is stacked column chart)….
but it was showing two same charts (both are pie charts) see the below diagram
I want to show the stacked column chart instead of pie chart in second one….but it was showing two same charts(pie )
i have divided the total form in to two areas …..
What I have to do to show the two different graphs on same form using single chart control
would any one pls help on this….
Many Thanks in advance for any ideas …..
This is a simple problem with the logic in your code.
Your code currently reads:
This obviously will always evaluate the first “if” to “true” and the second “if” to “false”. You need to reorganise your code so that it doesn’t use
arealike this – you need to step back and rewrite your logic that creates the charts you need.