试图在同一页面上显示两个图表

发布于 2024-11-25 12:31:23 字数 4625 浏览 1 评论 0原文

我正在使用 win 表单应用程序 我正在使用单个 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图表和来自数据库的数据是正确的

I am using win forms application
I am using single ms chart control and generating two different charts and want to show two on same page by using bool overview (this means when the applications runs one graph will be shown and if you click on that graph i want to show another one along with this one ) by the following code

      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
  {
  }
  }

but when the application runs it shows the graph and when i clicking on the graph it shows only one graph i dont know why it was not showing another graph

is there any mistake for specifying the series and legends for the ms chart and the data is coming from database is correct

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2024-12-02 12:31:23

查看您的代码,您正在数据绑定同一系列targetChartControl.Series[0]
我认为您需要尝试定义两个单独的图表系列并将它们分配给您已经定义的两个不同的图表区域。那应该可以解决你的问题。

Looking at your code, You are databinding the same series targetChartControl.Series[0].
I think you need to try defining two separate chart series and assign them to the two different chart areas that you already defined. That should solve your issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文