Example #1
0
        private String GetScript()
        {
            StringBuilder script = new StringBuilder();

            script.AppendLine("function ShowWatermark(evt, watermarkID, divId)");
            script.AppendLine("{");
            script.AppendLine("var svgDocument = evt.target.ownerDocument;");
//			script.AppendLine("svgDocument = null;");

            for (int i = 0; i < nChartControl1.Watermarks.Count; i++)
            {
                string watermarkId = new NElementIdentifier(nChartControl1.Watermarks[i].Id).ToString();
                script.AppendLine("svgDocument.getElementById(\"" + watermarkId + "\").setAttribute('style', 'visibility:hidden')");
            }

            script.AppendLine("if (svgDocument.getElementById(watermarkID))");
            script.AppendLine("{");
            script.AppendLine("	svgDocument.getElementById(watermarkID).setAttribute('style', 'visibility:visible')");
            script.AppendLine("}");

            script.AppendLine("parent.ShowDiv(divId);");
            script.AppendLine("}");

            return(script.ToString());
        }
Example #2
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // start document initialization
            Document = NDrawingView1.Document;
            Document.BeginInit();

            Document.Width  = NDrawingView1.Dimensions.Width;
            Document.Height = NDrawingView1.Dimensions.Height;

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(this.MapPathSecure(this.TemplateSourceDirectory + "\\MapOfUSA.xml"));

            XmlElement map = (XmlElement)xmlDocument.ChildNodes[0];

            Color[] stateColorTable = new Color[6];

            stateColorTable[0] = Color.LightPink;
            stateColorTable[1] = Color.Bisque;
            stateColorTable[2] = Color.Moccasin;
            stateColorTable[3] = Color.MistyRose;
            stateColorTable[4] = Color.PowderBlue;
            stateColorTable[5] = Color.Ivory;

            int   stateCounter       = 0;
            Color stateHighlighColor = Color.Orange;

            foreach (XmlElement state in map.ChildNodes)
            {
                string stateId = state.Attributes["Id"].Value.ToString();

                NCompositeShape stateShape = CreateState(state);
                // add to active layer
                Document.ActiveLayer.AddChild(stateShape);

//				NRotatedBoundsLabel label = new NRotatedBoundsLabel("Click to go to :" + stateId + " webpage", stateShape.UniqueId, new Nevron.Diagram.NMargins());
//				stateShape.Labels.AddChild(label);

                // set fill and stroke styles
                Color stateColor = stateColorTable[stateCounter % 6];

                stateShape.Style.FillStyle   = new NColorFillStyle(stateColor);
                stateShape.Style.StrokeStyle = new NStrokeStyle(1, Color.Black);

                NInteractivityStyle interactivityStyle = new NInteractivityStyle();
                stateShape.Style.InteractivityStyle = interactivityStyle;

                string elementId   = new NElementIdentifier(((INElement)stateShape.Primitives.GetChildAt(0)).Id).ToString();
                string stateScript = "onmouseover = 'HighlightState(\"" + elementId + "\", \"" + ColorToSVG(stateHighlighColor) + "\")' onmouseout = 'HighlightState(\"" + elementId + "\", \"" + ColorToSVG(stateColor) + "\")'";
                interactivityStyle.CustomMapAreaAttribute.JScriptAttribute = stateScript;
                interactivityStyle.UrlLink.Url             = "http://worldatlas.com/webimage/countrys/namerica/usstates/" + stateId.ToString() + ".htm";
                interactivityStyle.UrlLink.OpenInNewWindow = true;

                NElementIdentifier identifier = new NElementIdentifier(stateShape.Id);
                stateCounter++;
            }

            Document.BackgroundStyle.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.LightSeaGreen, Color.LightBlue);

            // change the response type to SVG
            NImageResponse response = new NImageResponse();

            NSvgImageFormat svgImageFormat = new NSvgImageFormat();

            svgImageFormat.EnableInteractivity = true;
            svgImageFormat.CustomScript        = GetScript();

            Hashtable attributes = new Hashtable();

            attributes["onload"]      = "Initialize(evt)";
            svgImageFormat.Attributes = attributes;
            response.ImageFormat      = svgImageFormat;

            NDrawingView1.ServerSettings.BrowserResponseSettings.DefaultResponse = response;
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            nChartControl1.Panels.Clear();

            // add watermarks

            string[] divIds = new string[] { "toyota",
                                             "chevrolet",
                                             "ford",
                                             "volkswagen",
                                             "hyundai",
                                             "nissan",
                                             "mazda" };

            nChartControl1.BackgroundStyle.FillStyle          = new NColorFillStyle(Color.LightGray);
            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // add header
            NLabel header = nChartControl1.Labels.AddHeader("Car Sales by Company");

            header.TextStyle.BackplaneStyle.Visible = false;
            header.TextStyle.TextFormat             = TextFormat.XML;
            header.TextStyle.ShadowStyle.Type       = ShadowType.GaussianBlur;
            header.TextStyle.FillStyle = new NColorFillStyle(Color.Black);
            header.DockMode            = PanelDockMode.Top;
            header.Margins             = new NMarginsL(0, 10, 0, 0);

            // by default the chart contains a cartesian chart which cannot display a pie series
            NDockPanel dockPanel = new NDockPanel();

            dockPanel.DockMode = PanelDockMode.Fill;
            dockPanel.PositionChildPanelsInContentBounds = true;
            dockPanel.Margins = new NMarginsL(10, 10, 10, 10);

            nChartControl1.Panels.Add(dockPanel);

            AddWatermark(dockPanel, "ToyotaLogo.png");
            AddWatermark(dockPanel, "ChevroletLogo.png");
            AddWatermark(dockPanel, "FordLogo.png");
            AddWatermark(dockPanel, "VolkswagenLogo.png");
            AddWatermark(dockPanel, "HyundaiLogo.png");
            AddWatermark(dockPanel, "NissanLogo.png");
            AddWatermark(dockPanel, "MazdaLogo.png");

            NPieChart pieChart = new NPieChart();

            dockPanel.ChildPanels.Add(pieChart);

            NPieSeries pieSeries = new NPieSeries();

            pieChart.Series.Add(pieSeries);

            // add some data
            pieSeries.AddDataPoint(new NDataPoint(11.6, "Toyota Corolla"));
            pieSeries.AddDataPoint(new NDataPoint(9.7, "Chevrolet Cruze"));
            pieSeries.AddDataPoint(new NDataPoint(9.3, "Ford Focus"));
            pieSeries.AddDataPoint(new NDataPoint(7.1, "Volkswagen Jetta"));
            pieSeries.AddDataPoint(new NDataPoint(7.0, "Hyundai Elantra"));
            pieSeries.AddDataPoint(new NDataPoint(6.1, "Nissan Versa"));
            pieSeries.AddDataPoint(new NDataPoint(5.9, "Mazda 3"));
            pieSeries.AddDataPoint(new NDataPoint(43.4, "Other"));

            pieSeries.PieStyle  = PieStyle.Torus;
            pieSeries.LabelMode = PieLabelMode.Center;

            // configure interactivity for data points
            for (int i = 0; i < pieSeries.Values.Count; i++)
            {
                NInteractivityStyle interactivityStyle = new NInteractivityStyle();

                if (i < nChartControl1.Watermarks.Count)
                {
                    string watermarkId = new NElementIdentifier(nChartControl1.Watermarks[i].Id).ToString();
                    interactivityStyle.CustomMapAreaAttribute.JScriptAttribute = "onmouseover = 'ShowWatermark(evt, \"" + watermarkId + "\", \"" + divIds[i] + "\")'";
                }
                else
                {
                    interactivityStyle.CustomMapAreaAttribute.JScriptAttribute = "onmouseover = 'ShowWatermark(evt, null, null)'";
                }

                pieSeries.InteractivityStyles.Add(i, interactivityStyle);
            }

            nChartControl1.InteractivityStyle.CustomMapAreaAttribute.JScriptAttribute = "onmouseover = 'ShowWatermark(evt, null, null)'";

            // apply style sheet
            NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.BrightMultiColor);

            styleSheet.Apply(nChartControl1.Document);

            // configure the control to generate SVG.
            NImageResponse  imageResponse  = new NImageResponse();
            NSvgImageFormat svgImageFormat = new NSvgImageFormat();

            svgImageFormat.EnableInteractivity = true;
            svgImageFormat.CustomScript        = GetScript();
            svgImageFormat.EmbedImagesInSvg    = true;
            svgImageFormat.EmbeddedImageFormat = new NJpegImageFormat();

            Hashtable attributes = new Hashtable();

            attributes["preserveAspectRatio"] = "yMid slice";
//			attributes["onload"] = "Initialize(evt)";
            svgImageFormat.Attributes = attributes;
            imageResponse.ImageFormat = svgImageFormat;

            nChartControl1.ServerSettings.BrowserResponseSettings.DefaultResponse = imageResponse;
        }