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);
            }
        }
Example #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);
        }
Example #3
0
        NDocument CreateDocument(NSize chartSize, NCustomToolsData.NData data, int populationDataId, int dataPointId)
        {
            NDocument document = new NDocument();

            document.RootPanel.Charts.Clear();

            // set a chart title
            string sex;
            string total;

            if (populationDataId == data.TotalFemaleData.Id)
            {
                sex   = "Female";
                total = string.Format("{0:0,#} +/-{1:0,#}", data.TotalFemaleData.Rows[dataPointId].Value, data.TotalFemaleData.Rows[dataPointId].Error);
            }
            else
            {
                sex   = "Male";
                total = string.Format("{0:0,#} +/-{1:0,#}", data.TotalMaleData.Rows[dataPointId].Value, data.TotalMaleData.Rows[dataPointId].Error);
            }
            NLabel header = document.RootPanel.Labels.AddHeader(string.Format("{0}, {1}, Population Data per Race<br/><font size='9pt'>Total of All Races: {2}</font>", sex, data.AgeRanges[dataPointId].Title, total));

            header.TextStyle.TextFormat = TextFormat.XML;
            header.TextStyle.FontStyle  = new NFontStyle("Times New Roman", 13, FontStyle.Italic);
            header.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Left;
            header.ContentAlignment = ContentAlignment.BottomRight;
            header.Location         = new NPointL(
                new NLength(3, NRelativeUnit.ParentPercentage),
                new NLength(3, NRelativeUnit.ParentPercentage));

            // add the chart
            NCartesianChart chart = new NCartesianChart();

            document.RootPanel.Charts.Add(chart);

            chart.SetPredefinedChartStyle(PredefinedChartStyle.HorizontalLeft);
            chart.Margins  = new NMarginsL(9, 40, 9, 9);
            chart.Location = new NPointL(
                new NLength(0, NRelativeUnit.ParentPercentage),
                new NLength(0, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(100, NRelativeUnit.ParentPercentage),
                new NLength(100, NRelativeUnit.ParentPercentage));
            chart.Width  = chartSize.Width + 180;
            chart.Height = chartSize.Height;

            NLinearScaleConfigurator scaleY = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator;

            scaleY.LabelValueFormatter = new NNumericValueFormatter("0,,.#M");

            NOrdinalScaleConfigurator scaleX = new NOrdinalScaleConfigurator();

            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;
            scaleX.AutoLabels              = false;
            scaleX.MajorTickMode           = MajorTickMode.CustomTicks;
            scaleX.CustomLabelFitModes     = new LabelFitMode[] { LabelFitMode.AutoScale };
            scaleX.CustomLabelsLevelOffset = new NLength(4);

            NBarSeries barSeries = chart.Series.Add(SeriesType.Bar) as NBarSeries;

            barSeries.DataLabelStyle.Visible = false;

            int length = data.Races.Count;

            for (int i = 0; i < length; i++)
            {
                NCustomToolsData.NRace race = data.Races[i];
                double value;
                if (populationDataId == race.MaleData.Id)
                {
                    value = race.MaleData.Rows[dataPointId].Value;
                }
                else
                {
                    value = race.FemaleData.Rows[dataPointId].Value;
                }
                barSeries.Values.Add(value);
                NCustomValueLabel vl = new NCustomValueLabel(i, race.Title);
                vl.Style.ContentAlignment = ContentAlignment.MiddleRight;
                scaleX.CustomLabels.Add(vl);
            }

            return(document);
        }