I am using the MSChart Control to plot some data but I would like to plot two different graphs
together on the same chart. For example, use a Bar chart (series1) with a pie chart (series2)
i am trying to show the two different graphs using one single chart by using following code
It was showing data correct but one problem is i want to show the two graphs (PIE CHART , BAR CHART ) but it was showing (“TWO PIE Charts”)
Can any one help on this
NOte : I am using one chart for all these operations
private void kpicartmouse_click(object sender, MouseEventArgs e)
{
Series acceptseries;
Series membershiptypeseries = null;
Title title;
string area;
try
{
var pos = e.Location;
var results = kpiChartControl.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
foreach (var result in results)
{
if (result.ChartElementType == ChartElementType.DataPoint)
{
DataTable visits = null;
visits = KPIData.Visits(dtStartDate.Value,dtEndDate.Value, mf);
DataTable accepts = null;
accepts = KPIData.AcceptedvisitsByMembership(mf);
area = "subchart";
kpiChartControl.ChartAreas.Add(area);
acceptseries = kpiChartControl.Series.Add(area);
acceptseries.ChartArea = area;
title = kpiChartControl.Titles.Add("Accepted Visits By MemberShip Type");
title.DockedToChartArea = area;
title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
title.Alignment = ContentAlignment.TopLeft;
kpiChartControl.Titles.Add("").DockedToChartArea = area;
kpiChartControl.Titles.Add("Accepted visits by memebrship types").DockedToChartArea = area;
foreach (Title titles in kpiChartControl.Titles)
{
titles.IsDockedInsideChartArea = false;
}
foreach (ChartArea chartArea in kpiChartControl.ChartAreas)
{
chartArea.Area3DStyle.Enable3D = true;
chartArea.Area3DStyle.Inclination = 45;
//chartArea.AxisX.LabelStyle.IsEndLabelVisible = !overview;
}
foreach (Series chartSeries in kpiChartControl.Series)
{
chartSeries.ChartType = SeriesChartType.StackedColumn;
chartSeries["ColumnDrawingStyle"] = "SoftEdge";
chartSeries["LabelStyle"] = "Top";
chartSeries.IsValueShownAsLabel = true;
chartSeries.BackGradientStyle = GradientStyle.DiagonalLeft;
}
foreach (Series chartSeries in kpiChartControl.Series)
{
chartSeries.ChartType = SeriesChartType.Pie;
chartSeries["PieLabelStyle"] = "Outside";
chartSeries["DoughnutRadius"] = "30";
chartSeries["PieDrawingStyle"] = "SoftEdge";
chartSeries.BackGradientStyle = GradientStyle.DiagonalLeft;
}
foreach (Legend legend in kpiChartControl.Legends)
{
legend.Enabled = false;
}
if (accepts == null)
{
acceptseries.Points.Clear();
acceptseries.Points.AddXY("no live", 0);
}
if (visits == null)
{
membershiptypeseries.Points.Clear();
membershiptypeseries.Points.AddXY("no membershiptypes", 0);
}
kpiChartControl.Series[0].Points.DataBindXY(accepts.Rows, "mshipname", accepts.Rows, "Value");
kpiChartControl.Series["subchart"].Points.DataBindXY(visits.Rows, "Status", visits.Rows, "Visits");
foreach (Series chartSeries in kpiChartControl.Series)
{
foreach (DataPoint point in chartSeries.Points)
{
switch (point.AxisLabel)
{
case "Accepted": point.Color = Color.Green; break;
case "Refused": point.Color = Color.Red; break;
}
point.Label = string.Format("{0:0}", point.YValues[0]);
}
}
foreach (Series chartSeries in kpiChartControl.Series)
{
foreach (DataPoint point in chartSeries.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}- {1}", point.YValues[0], point.AxisLabel);
}
}
}
}
}
catch
{
}
}
Just a guess… won’t this block of code force all your charts to be Pie charts?
If this doesn’t help, then try breaking your code down into smaller methods, then commenting each bit out in turn – then you’ll be able to understand what each bit does.