1
A
回答
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())
;
相關問題
- 1. 如何更改Mvc餅圖顏色?
- 2. 角度圖 - 更改圖表的顏色
- 3. 根據數據更改圖例顏色高圖表
- 4. Flotr2,顏色在圖上更改,圖例不更新
- 5. 更改圖像的顏色
- 6. 更改ImagePlus圖像顏色
- 7. 更改圖片顏色
- 8. 更改圖像顏色
- 9. Java更改圖像顏色
- 10. 更改圖像的顏色
- 11. 更改線的顏色組合圖表
- 12. 在devexpress圖表中更改顏色
- 13. 更改字幕顏色谷歌圖表
- 14. 谷歌圖表 - 更改欄顏色
- 15. 更改不同值的圖表顏色
- 16. extjs更改圖表軸標籤顏色
- 17. 更改某些圖表點的顏色
- 18. 更改列表視圖行的顏色
- 19. C#Excel圖表更改顏色
- 20. 在Primefaces圖表中更改顏色
- 21. 更改圖表控件軸顏色?
- 22. Python圖形更改軸標記顏色和圖例邊框顏色
- 23. 重新排列多線圖的顏色和圖例,並更改圖例圖標
- 24. Winform中MS圖表顏色和圖例
- 25. 更改高地圖地圖顏色
- 26. 使用Achartengine更改圖例文本的顏色(餅圖)
- 27. JavaFX StackedBarChart圖例顏色不遵循圖表顏色CSS樣式
- 28. 如何更改chartjs中圖例的顏色並能夠添加更多圖例?
- 29. jfreechart - 更改圖例中的顏色示例
- 30. 更改AmCharts庫存圖表中的圖表顏色
但我正在'System.Web.Helpers.Chart'類甚至沒有像'Palette'和'PaletteCustomColors'屬性:( – levi
@levi?在我的例子中我也使用System.Web.Helpers 。你可以使用我發佈的代碼嗎?然後再試一次嗎?如果這對你有效,你可以upvote :-) – Dave3of5
你很好。有用。你已經有了我的投票權。 – levi