2011-07-22 24 views
0

私はwinフォームアプリケーションを使用しています 私は単一のmsチャートコントロールを使用しており、2つの異なるチャートを生成しています。 1つのグラフが表示されますし、そのグラフをクリックした場合、私は次のコード同じページに2つのグラフを表示しようとしています

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

が、アプリケーションの実行時に、それはグラフを示し、私はグラフをクリックすることで)この1と一緒に別のものを表示したいです1つのグラフしか表示していない理由を知ることはできません。

msチャートのシリーズと凡例を指定するためのもので、データはデータベースから取得されています。

+0

伝説とシリーズに問題はありますか? – user682417

答えて

2

あなたのコードを見ると、同じシリーズのデータ​​をバインドしていますtargetChartControl.Series[0]。 2つの別々のチャートシリーズを定義し、既に定義した2つの異なるチャートエリアにそれらを割り当てる必要があると思います。それはあなたの問題を解決するはずです。

関連する問題