<%@ Page language="c#" MasterPageFile="~/SampleCode/SamplesMasterPage.master" Inherits="SmartWebControls.SampleCode.SmartChartRectangleRenderEventHtml" CodeFile="SmartChartRectangleRenderEventHtml.aspx.cs" %> <%@ Register TagPrefix="swc" Namespace="SmartWebControls" Assembly="SmartWebControls.SmartChart" %> <asp:Content ID="content" runat="server" ContentPlaceHolderID="cphMain"> <br /> <div id="divTitle"> Changing SmartChart entity colors using the SmartChartRectangleRender event.</div> <div id="divInstructions"> SmartChart provides a rich event model that allows developers to be notified as various items are being rendered. This example demonstrates how events can be used to change box colors based upon business rules. </div> <p></p> <swc:SmartChartPro ID="SmartChart1" Title="SmartChartRectangleRender Event Demo" runat="server" ShowToolbar="True" AllowEditing="True" AllowDragDrop="True" ShadowColor="LightGray" Font-Names="Verdana" Font-Bold="True" RoundBoxEdgesAmount="10" OutputType="Html" Height="472px" Width="750px" ImageWidth="90" ImageHeight="70" TitleColor="MidnightBlue" ShadowOffset="5" AllowDrillDown="True" BoxTextColor="White" BoxColor="Navy" MaxTextLength="25" DataFields="name,title,contact" DataKeyField="id" DataNodeName="person" DataTitleFields="name,desc,contact" BackgroundImage="" DrawShadows="True" HighlightChildrenOnMouseOver="True" ToolbarCssClass="toolbar" HasParentImagePath="~/SampleCode/SmartChartPro/Images/up.gif" HasChildrenImagePath="~/SampleCode/SmartChartPro/Images/down.gif" DrillDownType="SmartChartImage" HasChildrenImageVSpace="0" HasParentImageVSpace="8" ChartDepth="5" AllowDeleting="True"> </swc:SmartChartPro> <asp:Panel ID="pnlSave" runat="server" Visible="False"> <b>SmartChart data saved (see save event handler in code-behind file).</b> </asp:Panel> </asp:Content>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Xml; using System.Drawing.Drawing2D; namespace SmartWebControls.SampleCode { /// <summary> /// Summary description for OrgsTest. /// </summary> public partial class SmartChartRectangleRenderEventHtml : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { this.SmartChart1.SmartChartDeleting += new EventHandler<SmartChartEventArgs>(this.SmartChart1_SmartChartDeleting); this.SmartChart1.SmartChartSaving += new EventHandler<SmartChartSaveEventArgs>(this.SmartChart1_SmartChartSaving); this.SmartChart1.SmartChartRectangleRendering += new EventHandler<SmartChartEventArgs>(this.SmartChart1_SmartChartRectangleRendering); if (!Page.IsPostBack) { string xmlPath = Server.MapPath("~/SampleCode/SmartChartPro/XML/OrgChart.xml"); XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); //Hook up event to event handler SmartChart1.DataSource = doc; SmartChart1.DataBind(); } } /// <summary> /// Before the SmartChart renders the chart demonstrate how to change the background. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SmartChart1_SmartChartRectangleRendering(object sender, SmartWebControls.SmartChartEventArgs e) { if (e.Item.DataItem != null) { SmartWebControls.SmartChartItem item = e.Item; Color boxColor = Color.Empty; //Grab appropriate title key from DataKeyField values and use it to access the text value string title = item.DataItem["title"].ToString().ToLower(); if (title.IndexOf("mgr") != -1 || title.IndexOf("cio") != -1) { //Found a node that has what we want item.BackColor = Color.ForestGreen; item.ForeColor = Color.White; } if (title.IndexOf("developer") != -1) { //Found a node that has what we want item.ForeColor = Color.White; item.BackColor = Color.Firebrick; } if (title.IndexOf("admin") != -1) { item.DrawBorder = false; item.BackColor = Color.White; item.ForeColor = Color.Black; item.DrawShadows = false; } } } private void SmartChart1_SmartChartSaving(object sender, SmartChartSaveEventArgs e) { //Save data back to database or else where this.SmartChart1.Visible = false; this.pnlSave.Visible = true; XmlDocument doc = (XmlDocument)e.Result; //Save doc.... doc.Save(path); } private void SmartChart1_SmartChartDeleting(object sender, SmartWebControls.SmartChartEventArgs e) { } } }