Mit den Microsoft Chart Controls for Microsoft .NET Framework 3.5 lassen sich leicht und schnell Diagramme generieren. In Verbindung mit den HTTP-Enpoints in omniSuite können so vordefinierte Diagramme als Bild über eine URL zur Verfügung gestellt werden.
Das Installationspaket finden Sie unter http://www.microsoft.com/downloads/en/details.aspx?FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c
Installieren Sie es auf dem Rechner, auf dem der cmdbcore läuft.
Pfad: /mschart/ram_columns
Referenzen:
System.Windows.Forms.dll
System.Drawing.dll
C:\Programme\Microsoft Chart Controls\Assemblies\System.Windows.Forms.DataVisualization.dll
Usings:
System.Windows.Forms.DataVisualization.Charting
System.Windows.Forms
System.Drawing
System.Drawing.Imaging
System.Collections
<entry point>
// URL int pDomID=Request.QueryInt("pDomID"); string errmsg=""; // build SQL string sql="select HWM_RAM, count(*) as cnt from HWM where HWM_MDT_ID=1 and HWM_RAM<>0 "; if (pDomID!=0) sql+=" and HWM_DOM_ID=" + pDomID.ToString(); sql+=" group by HWM_RAM order by HWM_RAM"; // data als Hashtable (key=zeile_als_int, value=Hashtable(key=Spalte,value_als_string) ) Hashtable htData = db.ExecuteIntoHashtable(sql, out errmsg); // umwandeln in string[] und int[] string[] data_ram=new string[htData.Count]; int[] data_count=new int[htData.Count]; for (int i=0; i<htData.Count; i++) { Hashtable row=(Hashtable)htData[i]; data_ram[i]=(string)row["HWM_RAM"]; data_count[i]= int.Parse( (string)row["cnt"] ); } // chart erstellen Chart C = new Chart(); C.Width = 640; C.Height = 480; // Überschrift string title_text="Alle Rechner"; if (pDomID!=0) title_text="Rechner für Domäne " + db.ExecuteInto1Var("select DOM_NAME from DOM where DOM_ID=" + pDomID.ToString(), "", out errmsg); C.Titles.Add(new Title(title_text,Docking.Top,new Font("tahoma",14,FontStyle.Bold), Color.Black)); C.BackColor = System.Drawing.Color.FromArgb(243, 223, 193); C.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom; C.BorderlineColor = System.Drawing.Color.FromArgb(181, 64, 1); C.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid; C.BorderlineWidth = 2; C.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss; ChartArea CA = new ChartArea(); CA.BackGradientStyle = GradientStyle.Center; CA.Area3DStyle.Enable3D = true; C.ChartAreas.Add(CA); // Data Series ser1 = new Series(); ser1.ChartType = SeriesChartType.Column; ser1.Points.DataBindXY(data_ram, data_count); ser1.IsValueShownAsLabel = true; ser1.BackGradientStyle = GradientStyle.DiagonalLeft; C.Series.Add(ser1); CA.AxisX.Title = "RAM"; CA.AxisX.TitleFont = new Font("tahoma", 14); CA.AxisX.LabelStyle.Angle = -90; CA.AxisX.Interval = 1; CA.AxisY.Title = "Anzahl"; CA.AxisY.TitleFont = new Font("tahoma", 14); // retrieve image Bitmap bmp = new Bitmap(C.Width, C.Height); C.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height) ); System.IO.MemoryStream ms = new System.IO.MemoryStream(); bmp.Save(ms, ImageFormat.Png); // send image Response.ContentType = "image/png"; Response.SetRawContent(ms.GetBuffer());
Alle Rechner: http://server:port/mschart/ram_columns
Eine konkrete Domäne: http://server:port/mschart/ram_columns?pDomID=5