2014-03-05 44 views

回答

1

具有這仔細一看,我認爲這是你想要的東西:

http://truncatedcodr.wordpress.com/2012/09/18/system-web-helpers-chart-custom-themes/

,如果你的例子,我可以給這裏。

編輯:在這裏,我做了什麼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Drawing; 
using System.Web.UI.DataVisualization.Charting; 
using System.Text; 
using System.Xml; 

namespace MyMvcApplication 
{ 
    public class Theme 
    { 
     public static string GetTheme() 
     { 
      ChartArea ca = new System.Web.UI.DataVisualization.Charting.ChartArea("Default"); 
      var chart = new System.Web.UI.DataVisualization.Charting.Chart(); 
      chart.BackColor = Color.Azure; 
      chart.BackGradientStyle = GradientStyle.TopBottom; 
      chart.BackSecondaryColor = Color.White; 
      chart.BorderColor = Color.FromArgb(26, 59, 105); 
      chart.BorderlineDashStyle = ChartDashStyle.Solid; 
      chart.BorderWidth = 2; 
      chart.Palette = ChartColorPalette.None; 
      chart.PaletteCustomColors = new Color[] { Color.Lime, Color.Red, 
     Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Purple, 
     Color.Black }; 
      chart.ChartAreas.Add(new ChartArea("Default") 
      { 
       BackColor = Color.FromArgb(64, 165, 191, 228), 
       BackGradientStyle = GradientStyle.TopBottom, 
       BackSecondaryColor = Color.White, 
       BorderColor = Color.FromArgb(64, 64, 64, 64), 
       BorderDashStyle = ChartDashStyle.Solid, 
       ShadowColor = Color.Transparent, 
       Area3DStyle = new ChartArea3DStyle() 
       { 
        LightStyle = LightStyle.Simplistic, 
        Enable3D = true, 
        Inclination = 5, 
        IsClustered = true, 
        IsRightAngleAxes = true, 
        Perspective = 5, 
        Rotation = 0, 
        WallWidth = 0 
       } 
      }); 
      chart.Legends.Add(new Legend("All") 
       { 
        BackColor = Color.Transparent, 
        Font = new Font("Trebuchet MS", 8.25f, FontStyle.Bold, 
        GraphicsUnit.Point), 
        IsTextAutoFit = false 
       } 
       ); 
      chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss; 

      var cs = chart.Serializer; 
      cs.IsTemplateMode = true; 
      //cs.Content = SerializationContents.Appearance; 
      cs.Format = SerializationFormat.Xml; 
      var sb = new StringBuilder(); 
      XmlWriterSettings settings = new XmlWriterSettings(); 
      settings.OmitXmlDeclaration = true; 
      using (XmlWriter xw = XmlWriter.Create(sb, settings)) 
      { 
       cs.Save(xw); 
      } 
      string theme = sb.ToString(); 
      return theme; 
     } 
    } 
} 

更改PaletteCustomColors到你想要的顏色。您也可以使用各種樣式設置。

使用方法如下:

Chart myChart = new Chart(width: 600, height: 400, theme: MyMvcApplication.Theme.GetTheme());

+0

但我正在'System.Web.Helpers.Chart'類甚至沒有像'Palette'和'PaletteCustomColors'屬性:( – levi

+1

@levi?在我的例子中我也使用System.Web.Helpers 。你可以使用我發佈的代碼嗎?然後再試一次嗎?如果這對你有效,你可以upvote :-) – Dave3of5

+1

你很好。有用。你已經有了我的投票權。 – levi