试图在同一页面上显示两张图 [英] trying to show the two graphs on same page

查看:171
本文介绍了试图在同一页面上显示两张图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用win表单应用程序
我使用单个ms图表控件并生成两个不同的图表,并且希望通过使用bool概览在同一页面上显示两个图表(这意味着应用程序运行一个图形时将显示并如果你点击那个图表,我想显示另一个与这一个)通过下面的代码

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

是否有任何错误,用于指定ms图表的系列和图例,并且数据来自数据库是正确的

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

推荐答案

查看你的代码,你正在绑定相同的系列 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.

这篇关于试图在同一页面上显示两张图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆