2016-06-15 20 views
1

Ich habe ein MVC-Diagramm gezeichnet. enter image description hereAnpassen der MVC-Diagrammlegende?

Ich wollte nur wissen, wie man den Kreisseriennamen erreicht. enter image description here

Bitte helfen. Mein Code ist unten:

public ActionResult CreateBar() 
     { 

      // Create OnPremise and Azure Output Models 
      var objOnPremiseOutPut = new OnPremisesOutputModel(); 
      var objAzureOutPut = new AzureCostOutputModel(); 

      // Get the data from the TempData. Check :: What if the TemData is empty ?? 
      objOnPremiseOutPut = (OnPremisesOutputModel)TempData["TotalOnPremiseCost"]; 
      objAzureOutPut = (AzureCostOutputModel)TempData["TotalAzureCost"]; 

      // Create a new chart Object 
      var chart = new Chart(); 

      // Set Dimensions of chart 
      chart.Width = 500; 
      chart.Height = 350; 

      // Set Color and Background color properties 
      chart.BackColor = Color.WhiteSmoke;//Color.FromArgb(255, 255, 255); 
      chart.BorderlineDashStyle = ChartDashStyle.Solid; 
      chart.BackSecondaryColor = Color.White; 
      //chart.BackGradientStyle = GradientStyle.TopBottom; 
      chart.BorderlineWidth = 0; 
      chart.Palette = ChartColorPalette.BrightPastel; 
      chart.BorderlineColor = Color.FromArgb(26, 59, 105); 
      chart.RenderType = RenderType.BinaryStreaming; 
      chart.BorderSkin.SkinStyle = BorderSkinStyle.None; 
      chart.AntiAliasing = AntiAliasingStyles.All; 
      chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal; 

      // Set the Title and Legends for chart 
      chart.Titles.Add(CreateTitle()); 
      chart.Legends.Add(new Legend("Costs Distribution") 
      { 
       BackColor = Color.Transparent, 
       Font = new Font("Trebuchet MS", 8.25f, FontStyle.Bold, 
       GraphicsUnit.Point), 
       IsTextAutoFit = false 

      }); 


      // Clear any existing series and add the new series 
      chart.Series.Clear(); 
      chart.Series.Add(new Series()); 
      chart.Series.Add(new Series()); 
      chart.Series.Add(new Series()); 
      chart.Series.Add(new Series()); 

      foreach (Series s in chart.Series) 
      { 
       s.ChartType = SeriesChartType.StackedColumn; 
      } 
      //var totalStorage = objAzureOutPut.GeoReplicatedStorageAnnualExpense+objAzureOutPut.LocallyRedundantStorageAnnualExpense 
      //chart.Series["Default"].Points[0].AxisLabel = "On Premises"; 
      //chart.Series["Default"].Points[1].AxisLabel = "Azure"; 
      chart.Series[0].Points.Add(new DataPoint(0, objOnPremiseOutPut.TotalOnPremServerExpense)); 
      chart.Series[1].Points.Add(new DataPoint(0, objOnPremiseOutPut.TotalOnPremStorageCapacity)); 
      chart.Series[2].Points.Add(new DataPoint(0, objOnPremiseOutPut.TotalOnPremNetworkExpense)); 
      chart.Series[3].Points.Add(new DataPoint(0, objOnPremiseOutPut.TotalOnPremITExpense)); 

      //chart.Series[0].AxisLabel = "Azure"; 
      chart.Series[0].Points.Add(new DataPoint(1, objAzureOutPut.DiscVMPricingAnnualExpense)); 
      chart.Series[1].Points.Add(new DataPoint(1, objAzureOutPut.TotalStorageExpense)); 
      chart.Series[2].Points.Add(new DataPoint(1, objAzureOutPut.Zone1EgressAnnualExpense)); 
      chart.Series[3].Points.Add(new DataPoint(1, objAzureOutPut.AdminExpense)); 

      // Name the series 
      chart.Series["Series1"].Name = "Server"; 
      chart.Series["Series2"].Name = "Storage"; 
      chart.Series["Series3"].Name = "Network"; 
      chart.Series["Series4"].Name = "IT"; 
      chart.Series["IT"].MarkerStyle = MarkerStyle.Circle; 
      chart.Series["IT"].MarkerSize = 5; 

      // Create Memorysteam to dump the image 
      MemoryStream ms = new MemoryStream(); 
      CreateChartArea(chart).SaveImage(ms); 
      return File(ms.GetBuffer(), @"image/png"); 
     } 

     public Title CreateTitle() 
     { 
      Title title = new Title(); 
      title.Text = "Cost Comparison"; 
      title.ShadowColor = Color.FromArgb(32, 0, 0, 0); 
      title.Font = new Font("Trebuchet MS", 14F, FontStyle.Bold); 
      title.ShadowOffset = 3; 
      title.ForeColor = Color.FromArgb(26, 59, 105); 
      return title; 
     } 
     public Chart CreateChartArea(Chart chart) 
     { 
      ChartArea chartArea = new ChartArea(); 
      chartArea.Name = "Cost Comaparison"; 
      chartArea.BackColor = Color.WhiteSmoke; 

      // X Axis interval 
      chartArea.AxisX.Interval = 1; 

      // Set the Custom Labebls 
      CustomLabel onPremXLabel = new CustomLabel(-0.5, 0.5, "On Premise", 0, LabelMarkStyle.None); 
      CustomLabel azureXLabel = new CustomLabel(0.75, 1.25, "Azure", 0, LabelMarkStyle.None); 
      chartArea.AxisX.CustomLabels.Add(onPremXLabel); 
      chartArea.AxisX.CustomLabels.Add(azureXLabel); 


      //chartArea.AxisY.Title = "Costs (in $)"; 
      chartArea.AxisY.LabelStyle.Format = "C"; 
      //chartArea.AxisY.TitleFont = new Font("Verdana,Arial,Helvetica,sans-serif", 
      //   12F, FontStyle.Bold); 
      //chartArea.AxisX.LabelStyle.Font = 
      new Font("Verdana,Arial,Helvetica,sans-serif", 
        8F, FontStyle.Regular); 
      chartArea.AxisY.LabelStyle.Font = 
       new Font("Verdana,Arial,Helvetica,sans-serif", 
         8F, FontStyle.Regular); 
      chartArea.AxisY.LineColor = Color.FromArgb(64, 64, 64, 64); 
      chartArea.AxisX.LineColor = Color.FromArgb(64, 64, 64, 64); 
      chartArea.AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64); 
      chartArea.AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64); 

      chart.ChartAreas.Add(chartArea); 
      chart.ChartAreas["Cost Comaparison"].AxisY.MajorGrid.Enabled = false; 
      chart.ChartAreas["Cost Comaparison"].AxisX.MajorGrid.Enabled = false; 
      chartArea.AxisX.MinorTickMark.Enabled = false; 
      chartArea.AxisX.MajorTickMark.Enabled = false; 
      return chart; 
     }  

Antwort

1

Behandeln Sie das CustomizeLegend Ereignis, wie unten:

private void Chart1_CustomizeLegend(object sender, CustomizeLegendEventArgs e) 
    { 
     foreach (LegendItem li in e.LegendItems) 
     { 
      li.ImageStyle = LegendImageStyle.Marker; 
      li.MarkerStyle = MarkerStyle.Circle; 
      li.MarkerSize = 72; 
     } 
    } 

enter image description here

EDIT: Im Controller, nachdem das Diagramm erstellen, und vor der Rückgabe an die View, registrieren, um das Ereignis zu behandeln, wie folgt:

  chart1.CustomizeLegend += Chart1_CustomizeLegend; 
+0

Könnten Sie mir bitte zeigen, wie man Event in MVC behandelt. Wie ich ein ganz neues zu MVC –

+0

Bitte lesen Sie meinen aktualisierten Beitrag zur Registrierung für den Umgang mit der Veranstaltung. – jsanalytics

+0

Thanku Sooo viel –