trying to show the two graphs on same page

旧时模样 提交于 2020-01-06 15:29:14

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6791311/trying-to-show-the-two-graphs-on-same-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!