试图展示同一页上的两个图(trying to show the two graphs on same

2019-10-30 00:20发布

我使用我使用单MS图表控件,并产生两个不同的图表,并希望通过使用布尔概览显示两个同一页上赢窗体应用程序(这意味着当应用程序运行一个图形将显示,如果你点击该图我想下面的代码,以显示与这一个沿着另一个)

      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图表的系列传说和数据从数据库中来是正确的

Answer 1:

看你的代码,你是数据绑定同一系列targetChartControl.Series[0] 我想你需要尝试定义两个单独的图表系列和分配他们到你已经定义了两个不同的图表区域。 这应该解决您的问题。



文章来源: trying to show the two graphs on same page