protected void Page_Load(object sender, System.EventArgs e)
        {
            nChartControl1.AjaxToolsFactoryType = "NCustomToolFactory";

            if (nChartControl1.RequiresInitialization)
            {
                NCustomToolsData.NData data = NCustomToolsData.Read();

                nChartControl1.BackgroundStyle.FrameStyle.Visible = false;
                nChartControl1.Charts.Clear();

                //	display the female population chart
                NCartesianChart fChart = new NCartesianChart();

                fChart.SetPredefinedChartStyle(PredefinedChartStyle.HorizontalRight);
                fChart.Margins  = new NMarginsL(9, 0, 0, 0);
                fChart.Location = new NPointL(
                    new NLength(0, NRelativeUnit.ParentPercentage),
                    new NLength(0, NRelativeUnit.ParentPercentage));
                fChart.Size = new NSizeL(
                    new NLength(54.21f, NRelativeUnit.ParentPercentage),
                    new NLength(100, NRelativeUnit.ParentPercentage));
                nChartControl1.Charts.Add(fChart);

                InitializeChartData(fChart, data.TotalFemaleData, true, Color.Pink);

                NAxis axisX = fChart.Axis(StandardAxis.PrimaryX);
                NLinearScaleConfigurator scaleX = axisX.ScaleConfigurator as NLinearScaleConfigurator;
                scaleX.CustomLabelsLevelOffset = new NLength(4);

                int nRowCount = data.TotalMaleData.Rows.Count;
                for (int i = 0; i < nRowCount; i++)
                {
                    NCustomToolsData.NPopulationDataEntry en = data.TotalMaleData.Rows[i];
                    double begin = en.AgeRange.Start;
                    double end   = en.AgeRange.End + 1;
                    scaleX.CustomLabels.Add(new NCustomValueLabel((begin + end) / 2, en.AgeRange.Title));
                }

                //	display the male population chart
                NCartesianChart mChart = new NCartesianChart();

                mChart.SetPredefinedChartStyle(PredefinedChartStyle.HorizontalLeft);
                mChart.Margins  = new NMarginsL(0, 0, 9, 0);
                mChart.Location = new NPointL(
                    new NLength(55.5f, NRelativeUnit.ParentPercentage),
                    new NLength(0, NRelativeUnit.ParentPercentage));
                mChart.Size = new NSizeL(
                    new NLength(44.8f, NRelativeUnit.ParentPercentage),
                    new NLength(100, NRelativeUnit.ParentPercentage));
                nChartControl1.Charts.Add(mChart);

                InitializeChartData(mChart, data.TotalMaleData, false, Color.SkyBlue);
            }
        }
Exemple #2
0
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            int populationDataId;
            int dataPointId;

            if (context.Request["id"] == null)
            {
                return;
            }

            string[] tokens = context.Request["id"].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length != 2)
            {
                return;
            }

            if (!int.TryParse(tokens[0], out populationDataId))
            {
                return;
            }
            if (!int.TryParse(tokens[1], out dataPointId))
            {
                return;
            }

            NCustomToolsData.NData data = NCustomToolsData.Read();

            MemoryStream    ms          = new MemoryStream();
            NSize           chartSize   = new NSize(500, 200);
            NDocument       document    = CreateDocument(chartSize, data, populationDataId, dataPointId);
            NPngImageFormat imageFormat = new NPngImageFormat();

            using (INImage image = CreateImage(document, chartSize, imageFormat))
            {
                document.Refresh();
                image.SaveToStream(ms, imageFormat);
            }

            byte[] bytes = ms.GetBuffer();
            context.Response.ContentType = "image/png";
            context.Response.OutputStream.Write(bytes, 0, bytes.Length);
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
        }