我正在使用win表单应用程序 我正在使用单个ms图表控件并生成两个不同的图表,并希望通过使用bool概述在同一页面上显示两个(这意味着当应用程序运行时将显示一个图表,如果您单击该图表,我想要显示另一个图表用这一个)通过以下代码
private void chartControlMemberTotals_Click(object sender, EventArgs e)
{
kpiMemberTotalsForm.DrawKpi(this.chartControlMemberTotals, startDate, endDate, true);
}
public void DrawKpi(Chart targetChartControl, DateTime StartDate, DateTime EndDate, bool Overview)
{
try
{
Series series = null;
Title title;
string area;
targetChartControl.ChartAreas.Clear();
targetChartControl.Series.Clear();
targetChartControl.Titles.Clear();
area = "Status";
targetChartControl.ChartAreas.Add(area);
series = targetChartControl.Series.Add(area);
series.ChartArea = area;
if (!Overview)
{
title = targetChartControl.Titles.Add("Member status");
title.IsDockedInsideChartArea = Overview;
title.Alignment = ContentAlignment.TopLeft;
title.DockedToChartArea = area;
targetChartControl.Titles.Add("").DockedToChartArea = area;
}
targetChartControl.Titles.Add("Members status").DockedToChartArea = area;
area = " Live members mebershiptypes";
targetChartControl.ChartAreas.Add(area);
series = targetChartControl.Series.Add(area);
series.ChartArea = area;
if (!Overview)
{
title = targetChartControl.Titles.Add("Live Status members By MemberShip Type");
title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
title.Alignment = ContentAlignment.TopLeft;
title.DockedToChartArea = area;
targetChartControl.Titles.Add("").DockedToChartArea = area;
targetChartControl.Titles.Add("Live memberships").DockedToChartArea = area;
}
foreach (Title chartTitle in targetChartControl.Titles)
{
chartTitle.IsDockedInsideChartArea = false;
}
foreach (ChartArea chartArea in targetChartControl.ChartAreas)
{
chartArea.Area3DStyle.Enable3D = true;
chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;
}
if (!Overview)
{
foreach (Series chartSerie in targetChartControl.Series)
{
chartSerie.ChartType = SeriesChartType.StackedColumn;
chartSerie["ColumnDrawingStyle"] = "SoftEdge";
chartSerie["LabelStyle"] = "Top";
chartSerie.IsValueShownAsLabel = true;
//series.CustomProperties = "DrawingStyle=Cylinder";
chartSerie.BackGradientStyle = GradientStyle.DiagonalLeft;
}
}
foreach (Series chartSeries in targetChartControl.Series)
{
chartSeries.ChartType = SeriesChartType.Pie;
if (!Overview)
{
chartSeries["PieLabelStyle"] = "Outside";
}
else
{
chartSeries["PieLabelStyle"] = "Disabled";
}
chartSeries["DoughnutRadius"] = "30";
chartSeries["PieDrawingStyle"] = "SoftEdge";
chartSeries.BackGradientStyle = GradientStyle.DiagonalLeft;
}
foreach (Legend legend in targetChartControl.Legends)
{
legend.Enabled = false;
}
if (!Overview)
{
DataTable Accept = null;
Accept = KPIData.livemembersmembershiptype(mf);
targetChartControl.Series[0].Points.DataBindXY(Accept.Rows, "mshipname", Accept.Rows, "count");
foreach (Series chartSeries in targetChartControl.Series)
{
foreach (DataPoint point in chartSeries.Points)
{
switch (point.AxisLabel)
{
case "Silver membership": point.Color = Color.Red; break;
}
point.Label = string.Format("{0:0}", point.YValues[0]);
}
}
}
DataTable reportsfull = null;
reportsfull = KPIData.MembershipTotals(StartDate, EndDate, mf);
targetChartControl.Series[0].Points.DataBindXY(reportsfull.Rows, "Status", reportsfull.Rows, "Value");
foreach (Series chartSeries in targetChartControl.Series)
{
foreach (DataPoint point in chartSeries.Points)
{
switch (point.AxisLabel)
{
case "New": point.Color = Color.Cyan; break;
case "Live": point.Color = Color.Green; break;
}
point.Label = string.Format("{0:0} - {1}", point.YValues[0], point.AxisLabel);
}
}
}
catch
{
}
}
但是当应用程序运行时它显示图表,当我点击图表时它只显示一个图表我不知道为什么它没有显示另一个图表
指定ms图表的系列和图例是否有任何错误,数据来自数据库是否正确
答案 0 :(得分:2)
查看代码,您正在对同一系列targetChartControl.Series[0]
进行数据绑定。
我认为您需要尝试定义两个单独的图表系列并将它们分配给您已定义的两个不同的图表区域。这应该可以解决你的问题。