動態生成雷達圖--Radarhtml
效果圖:this
aspx頁面代碼:spa
1 <ext:Panel ID="ResultPanel" Border="true" runat="server"> 2 <Items> 3 </Items> 4 </ext:Panel>
由於是動態生成圖,因此只須要一個容器裝載(Panel);.net
aspx.cs代碼插件
1 [DirectMethod(Timeout = 2000000)]//限制執行超時時間 2 protected void ReloadData(object sender, DirectEventArgs e) 3 { 4 Dictionary<string, Dictionary<string, double>> data = GenerateChartBySingleCorp(); 5 ResultPanel.Controls.Clear(); 6 Ext.Net.Panel Panel = GetGroupChart(data); 7 ResultPanel.Add(Panel);//把生成帶有Radar圖的Panel加到容器裏 8 ResultPanel.ReRender();//從新裝載容器(容器位置不變) 9 // ResultPanel.Render();從新裝載容器(容器位置根據添加子元素的順序加載) 10 }
1 public Ext.Net.Panel GetGroupChart(Dictionary<string, Dictionary<string, double>> data ) 2 { 3 List<Datas> DataList = GetDataSource(data);//數據源 4 5 Ext.Net.Model ExtModel = new Ext.Net.Model();//定義一個mode 6 ExtModel.Fields.Add(new ModelField("Name", ModelFieldType.String)); 7 Dictionary<string, double> first=data.First().Value; 8 Dictionary<string, string> dataMODE = new Dictionary<string, string>(); 9 int i = 0; 10 foreach (var item in first) 11 { 12 ExtModel.Fields.Add(new ModelField("Data"+i, ModelFieldType.Float)); 13 dataMODE.Add("Data"+i,item.Key); 14 i++; 15 } 16 17 RadialAxis ra = new RadialAxis();//定義圖表類型,這裏定義爲 雷達圖,也能夠定義爲線圖,柱圖,餅圖等。 18 ra.Maximum = 5;//最大值 19 ra.Steps = 5;//分紅幾個圈 20 //Maximum="5" Steps="5" 21 22 Chart Chart = new Chart();//定義一個chart容器 23 Chart.Height = 500; 24 Chart.Width = 950; 25 Chart.StyleSpec = "background:#fff;"; 26 Chart.StandardTheme = StandardChartTheme.Category2; 27 Chart.InsetPadding = 20; 28 Chart.Animate = true; 29 Chart.LegendConfig = new ChartLegend(new ChartLegend.Config() { Position = LegendPosition.Right }); 30 foreach (var item in dataMODE)//循環加載數據集 31 { 32 RadarSeries radarseries = new RadarSeries(); 33 List<string> XFieldFields = new List<string>(); 34 XFieldFields.Add("Name"); 35 List<string> YFieldFields = new List<string>(); 36 YFieldFields.Add(item.Key); 37 radarseries.XField = XFieldFields.ToArray(); 38 radarseries.YField = YFieldFields.ToArray(); 39 radarseries.ShowInLegend = true; 40 radarseries.ShowMarkers = true; 41 radarseries.Title = item.Value; 42 43 SpriteAttributes SpriteAttributes = new Ext.Net.SpriteAttributes(); 44 SpriteAttributes.Radius = 5; 45 SpriteAttributes.Size = 5; 46 radarseries.MarkerConfig = SpriteAttributes; 47 48 SpriteAttributes SpriteAttributes1 = new Ext.Net.SpriteAttributes(); 49 SpriteAttributes1.StrokeWidth = 2; 50 SpriteAttributes1.Fill = "none"; 51 radarseries.Style = SpriteAttributes1; 52 53 ChartTip ChartTip = new Ext.Net.ChartTip(); 54 ChartTip.TrackMouse = true; 55 ChartTip.Width = 250; 56 ChartTip.Height = 28; 57 ChartTip.Renderer.Handler = "this.setTitle(storeItem.get('Name') + ': ' + storeItem.get('" + item.Key + "'));"; 58 radarseries.Tips = ChartTip; 59 Chart.Series.Add(radarseries); 60 } 61 Chart.Axes.Add(ra); 62 Store Store = new Ext.Net.Store(); 63 Store.Model.Add(ExtModel); 64 Store.Data = DataList; 65 Store.AutoDataBind = true; 66 Chart.Store.Add(Store); 67 68 Ext.Net.Panel Panelp = new Ext.Net.Panel(); 69 Panelp.Border = false; 70 Panelp.Height = 560; 71 Panelp.Width = 960; 72 Panelp.Add(Chart); 73 return Panelp; 74 }
圖表總結code
和雷達圖同樣,其餘圖表也是相似的定義,只是屬性不一樣而已。具體可參考ext.net 提供的demo http://examples.ext.net/#/Chart/Area/Basic/server
小白在項目中用到的其餘優秀的圖表插件htm
fashion chartblog
http://www.fusioncharts.com/ip
Highcharts
這兩款都是比較優秀的圖表插件。固然就雷達圖而言,小白以爲仍是ext的比較漂亮。
更多圖表請看小白的博文 http://www.cnblogs.com/WangJinYang/archive/2012/06/19/2554594.html
歡迎博友的意見和建議。