//Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // The data for the area chart
            double[] data = { 3.0, 2.8, 4.0, 5.5, 7.5, 6.8, 5.4, 6.0, 5.0, 6.2, 7.5,
                              6.5, 7.5, 8.1, 6.0, 5.5, 5.3, 3.5, 5.0, 6.6, 5.6, 4.8, 5.2, 6.5, 6.2 }

            ;

            // The labels for the area chart
            string[] labels = { "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",  "9",
                                "10", "11", "12", "13", "14", "15", "16", "17", "18", "19","20",
                                "21", "22", "23", "24" };

            // Create a XYChart object of size 300 x 180 pixels. Set the background
            // to pale yellow (0xffffa0) with a black border (0x0)
            XYChart c = new XYChart(300, 180, 0xffffa0, 0x000000);

            // Set the plotarea at (45, 35) and of size 240 x 120 pixels. Set the
            // background to white (0xffffff). Set both horizontal and vertical grid
            // lines to black (&H0&) dotted lines (pattern code 0x0103)
            c.setPlotArea(45, 35, 240, 120, 0xffffff, -1, -1, c.dashLineColor(
                              0x000000, 0x000103), c.dashLineColor(0x000000, 0x000103));

            // Add a title to the chart using 10 pts Arial Bold font. Use a 1 x 2
            // bitmap pattern as the background. Set the border to black (0x0).
            c.addTitle("Snow Percipitation (Dec 12)", "Arial Bold", 10
                       ).setBackground(c.patternColor(new int[] { 0xb0b0f0, 0xe0e0ff }, 2),
                                       0x000000);

            // Add a title to the y axis
            c.yAxis().setTitle("mm per hour");

            // Set the labels on the x axis.
            c.xAxis().setLabels(labels);

            // Display 1 out of 3 labels on the x-axis.
            c.xAxis().setLabelStep(3);

            // Add an area layer to the chart
            AreaLayer layer = c.addAreaLayer();

            // Load a snow pattern from an external file "snow.png".
            int snowPattern = c.patternColor2("snow.png");

            // Add a data set to the area layer using the snow pattern as the fill
            // color. Use deep blue (0x0000ff) as the area border line color
            // (&H0000ff&)
            layer.addDataSet(data).setDataColor(snowPattern, 0x0000ff);

            // Set the line width to 2 pixels to highlight the line
            layer.setLineWidth(2);

            // Output the chart
            viewer.Image = c.makeImage();

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{xLabel}:00 - {value} mm/hour'");
        }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // Data for the chart
            double[] data0  = { 100, 125, 245, 147, 67, 96, 160, 145, 97, 167, 220, 125 };
            double[] data1  = { 85, 156, 179, 211, 123, 225, 127, 99, 111, 260, 175, 156 };
            double[] data2  = { 97, 87, 56, 267, 157, 157, 67, 156, 77, 87, 197, 87 };
            string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct",
                                "Nov", "Dec" };

            // Create a XYChart object of size 560 x 280 pixels.
            XYChart c = new XYChart(560, 280);

            // Add a title to the chart using 14pt Arial Bold Italic font
            c.addTitle("     Average Weekly Network Load", "Arial Bold Italic", 14);

            // Set the plotarea at (50, 50) and of 500 x 200 pixels in size. Use alternating light grey
            // (f8f8f8) / white (ffffff) background. Set border to transparent and use grey (CCCCCC)
            // dotted lines as horizontal and vertical grid lines
            c.setPlotArea(50, 50, 500, 200, 0xffffff, 0xf8f8f8, Chart.Transparent, c.dashLineColor(
                              0xcccccc, Chart.DotLine), c.dashLineColor(0xcccccc, Chart.DotLine));

            // Add a legend box at (50, 22) using horizontal layout. Use 10 pt Arial Bold Italic font,
            // with transparent background
            c.addLegend(50, 22, false, "Arial Bold Italic", 10).setBackground(Chart.Transparent);

            // Set the x axis labels
            c.xAxis().setLabels(labels);

            // Draw the ticks between label positions (instead of at label positions)
            c.xAxis().setTickOffset(0.5);

            // Add axis title
            c.yAxis().setTitle("Throughput (MBytes Per Hour)");

            // Set axis line width to 2 pixels
            c.xAxis().setWidth(2);
            c.yAxis().setWidth(2);

            // Add a multi-bar layer with 3 data sets
            BarLayer layer = c.addBarLayer2(Chart.Side);

            layer.addDataSet(data0, 0xff0000, "Server #1");
            layer.addDataSet(data1, 0x00ff00, "Server #2");
            layer.addDataSet(data2, 0x0000ff, "Server #3");

            // Set bar shape to circular (cylinder)
            layer.setBarShape(Chart.CircleShape);

            // Configure the bars within a group to touch each others (no gap)
            layer.setBarGap(0.2, Chart.TouchBar);

            // Output the chart
            viewer.Image = c.makeWebImage(Chart.PNG);

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "",
                                                "title='{dataSetName} on {xLabel}: {value} MBytes/hour'");
        }
Exemple #3
0
        public void createChart()
        {
            string[] xLabels = null;
            if (data.Count != 0)
            {
                xLabels = new string[data.Count];

                for (int i = 0; i < xLabels.Length; i++)
                {
                    xLabels[i] = (i + 1).ToString();
                }
            }

            XYChart c = new XYChart(795, 455);

            c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888);

            //LegendBox legendBox = c.addLegend(450, 80, false, "Arial", 8);
            //legendBox.setAlignment(Chart.BottomCenter);
            //legendBox.setBackground(Chart.Transparent, Chart.Transparent);
            //legendBox.setLineStyleKey();
            //legendBox.setFontSize(8);

            ChartDirector.TextBox title = c.addTitle("傅里叶数据分析", "Arial Bold", 13);
            title.setPos(0, 20);

            c.setPlotArea(50, 60, 730, 345, 0xffffff, -1, -1, c.dashLineColor(
                              0xaaaaaa, Chart.DotLine), -1);

            c.xAxis().setLabels(xLabels);
            c.xAxis().setLabelStep(9);
            c.xAxis().setIndent(true);
            c.xAxis().setTitle("数据序号");
            c.yAxis().setTitle("数据值").setAlignment(Chart.TopLeft2);

            LineLayer layer;
            int       hzColor = Chart.CColor(Color.DeepPink);

            layer = c.addLineLayer2();
            layer.addDataSet(data.ToArray(), hzColor, "数据值");            //.setDataSymbol(Chart.CircleSymbol, 3); ;
            layer.setLineWidth(2);
            layer.setFastLineMode();

            if (minX == maxX)
            {
                c.layout();
                minX = c.xAxis().getMinValue();
                minY = c.yAxis().getMinValue();
                maxX = c.xAxis().getMaxValue();
                maxY = c.yAxis().getMaxValue();
            }

            //SetXYChartScale(minX, minY, maxX, maxY, winChartViewer1, c);
            //winChartViewer1.syncLinearAxisWithViewPort("x", c.xAxis());
            //winChartViewer1.syncLinearAxisWithViewPort("y", c.yAxis());

            winChartViewer1.Chart    = c;
            winChartViewer1.ImageMap =
                winChartViewer1.Chart.getHTMLImageMap("clickable", "", "title='数据序号: {xLabel}, {dataSetName}: {value}'");
        }
        public byte[] CreateChart(IList<ChartItemParm> dateItem,
            string[] labels, string title, string bottom_text, string left_text, string scaleFromat)
        {
            string font_1 = "微軟正黑體";
            string font_2 = "新細明體";

            int CanvasWidth = CommWebSetup.Chart_Canvas_Width;
            int DiagramWidth = CommWebSetup.Chart_Diagram_Width;

            XYChart xyCht = new XYChart(CanvasWidth, CommWebSetup.Chart_Canvas_Height, CommWebSetup.Chart_Canvas_BgColor, CommWebSetup.Chart_Canvas_EdgeColor, 1); //設定畫布區大小
            //parm 5:奇數列顏色
            //parm 6:偶數列顏色
            //parm 7:外框顏色
            xyCht.setPlotArea(72, 90, DiagramWidth, CommWebSetup.Chart_Diagram_Height, 0xefefef, 0xfefefe, Chart.Transparent, 0x999999, 0x999999); //繪制圖表的位置及大小

            xyCht.setRoundedFrame();

            TextBox getTitleText = xyCht.addTitle(title, CommWebSetup.Chart_Title_FontFamily, CommWebSetup.Chart_Title_FontSize, CommWebSetup.Chart_Title_FontColor, CommWebSetup.Chart_Title_BgColor);
            getTitleText.setHeight(CommWebSetup.Chart_Title_Height);
            getTitleText.setAlignment(Chart.Center);

            //設定上方資訊綜合區
            LegendBox legendBox = xyCht.addLegend(72, getTitleText.getHeight(), false, font_1, 10);
            legendBox.setAlignment(Chart.TopLeft);
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);

            //左側處理
            TextBox getY = xyCht.yAxis().setTitle(left_text, font_2, 14);
            getY.setFontAngle(0, true);
            xyCht.yAxis().setWidth(2);
            getY.setHeight(CommWebSetup.Chart_Diagram_Height);

            var getScaleText = xyCht.yAxis().setLabelStyle(font_2, 9);

            if (scaleFromat != null)
            {
                xyCht.yAxis().setLabelFormat(scaleFromat); //設定左邊刻度格式
                //xyCht.yAxis().setLabelFormat("{value}度");
            }

            //底部處理
            var getBottomText = xyCht.xAxis().setTitle(bottom_text, font_1,14);
            var getBottomlabel = xyCht.xAxis().setLabels(labels);
            getBottomlabel.setFontSize(9);
            getBottomlabel.setFontStyle(font_2);
            //xyCht.xAxis().setLabelStep(3); //設定Label間隔(橫向) 如果Label太密集可在此設定

            foreach (var getItem in dateItem)
            {
                LineLayer setLine = xyCht.addLineLayer2();
                setLine.addDataSet(getItem.getData, getItem.color, getItem.name).setDataSymbol(Chart.GlassSphere2Shape, 9);
                setLine.setLineWidth(2);
                setLine.setGapColor(xyCht.dashLineColor(getItem.color)); //設定無值顏色

            }
            //c.layoutLegend();
            return xyCht.makeChart(Chart.PNG);
        }
Exemple #5
0
        private void UpdatePlot(object sender, RunWorkerCompletedEventArgs e)
        {
            List <object> objlist = new List <object>();

            objlist.AddRange((List <object>)e.Result);
            double[] depart    = (double[])objlist[0];
            double[] arrive    = (double[])objlist[1];
            double[] departVel = (double[])objlist[2];
            string   Plan1Name = (string)objlist[3];
            string   Plan2Name = (string)objlist[4];

            XYChart c = new XYChart(800, 800);

            c.setPlotArea(75, 40, 600, 600, -1, -1, -1, c.dashLineColor(unchecked ((int)0x80000000), Chart.DotLine), -1);
            // When auto-scaling, use tick spacing of 40 pixels as a guideline
            c.yAxis().setTickDensity(40);
            c.xAxis().setTickDensity(40);


            // Add a contour layer using the given data
            ContourLayer layer = c.addContourLayer(depart, arrive, departVel);

            c.getPlotArea().moveGridBefore(layer);
            ColorAxis cAxis = layer.setColorAxis(700, 40, Chart.TopLeft, 400, Chart.Right);

            double[] colorScale = { 3, 0x090446, 3.3, 0x16366B, 3.6, 0x236890, 3.9, 0x309AB5, 4.2, 0x53C45A, 4.5, 0x77EF00, 4.8, 0xBBF70F, 5.1, 0xFFFF1E, 5.4, 0xFF8111, 5.7, 0xFF0404 };
            cAxis.setColorScale(colorScale, 0x090446, 0xffffff);
            cAxis.setColorGradient(false);
            // Add a title to the color axis using 12 points Arial Bold Italic font
            cAxis.setTitle("Departure Velocity (km/s)", "Arial Bold Italic", 12);
            c.xAxis().setTitle("Departure Date (JDCT)");
            c.yAxis().setTitle("Arrival Date (JDCT)");
            c.addTitle("Departure Velocity from " + Plan1Name + " to " + Plan2Name);
            c.xAxis().setTickLength(10);
            c.yAxis().setTickLength(10);


            // Output the chart
            winChartViewer1.Chart    = c;
            winChartViewer1.ImageMap = c.getHTMLImageMap("");

            /*
             *          // The data for the bar chart
             * double[] data = {85, 156, 179.5, 211, 123};
             *
             * // The labels for the bar chart
             * string[] labels = { "Mon", "Tue", "Wed", "Thu", "Fri" };
             *
             * XYChart c = new XYChart(250, 250);
             * c.setPlotArea(30, 20, 200, 200);
             * c.addBarLayer(data);
             * c.xAxis().setLabels(labels);
             * winChartViewer1.Chart = c;
             */
        }
        private void createChartModel(WinChartViewer viewer, DataTable errorData, int per)
        {
            try
            {
                Chart.setLicenseCode("DEVP-2LSU-B4LX-YCTY-2DF2-77EE");
                this.chartWidth = this.Width;
                //  plottWidth = chartWidth - 80;
                double[] data = null;
                //int[] color = null;
                string[] labels = null;
                GetDataFChartModel(errorData, ref labels, ref data);

                XYChart c = new XYChart(viewer.Width, viewer.Height);
                c.setBorder(10);
                //c.setBackground(0xFFFFFF);


                c.setPlotArea(70, 90, viewer.Width - 100, viewer.Height - 270, Chart.Transparent,
                              -1, Chart.Transparent, c.dashLineColor(0xffffff, Chart.Transparent));
                ArrayMath am = new ArrayMath(data);
                viewer.BorderStyle = BorderStyle.None;


                c.yAxis().setLinearScale(0, am.max() + 10);
                BarLayer layer = c.addBarLayer(am.mul(percentage / 100.0).result(), 0x30c2f7);

                c.addTitle(" BY MODEL", "Calibri Bold", 30).setBackground(Chart.metalColor(0xff9999));

                //title.setMargin2(10, 10, 12, 12);
                layer.setBarShape(Chart.CircleShape, 0);


                layer.set3D(20, 10);

                layer.setAggregateLabelStyle("Arial Bold", 14, layer.yZoneColor(0,
                                                                                0xcc3300, 0x3333ff));

                c.xAxis().setLabels(labels);
                c.xAxis().setLabelStyle("Arial Bold", 9).setFontAngle(45);
                c.yAxis().setLabelStyle("Arial Bold", 12);

                viewer.Chart = c;
                //viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                //    "title='{xLabel}: {value}'");
            }
            catch (Exception)
            {
            }
        }
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the chart
            double[] data0 = { 42, 49, Chart.NoValue, 38, 64, 56, 29, 41, 44, 57 };
            double[] data1 = { 65, 75, 47, 34, 42, 49, 73, Chart.NoValue, 90, 69, 66, 78 };
            double[] data2 = { Chart.NoValue, Chart.NoValue, 25, 28, 38, 20, 22, Chart.NoValue, 25,
                               33,                       30, 24 };
            string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
                                "Nov", "Dec" };

            // Create a XYChart object of size 600 x 360 pixels. Set background color to brushed
            // silver, with a 2 pixel 3D border. Use rounded corners.
            XYChart c = new XYChart(600, 360, Chart.brushedSilverColor(), Chart.Transparent, 2);

            c.setRoundedFrame();

            // Add a title using 18pt Times New Roman Bold Italic font. #Set top/bottom margins to 6
            // pixels.
            ChartDirector.TextBox title = c.addTitle("Product Line Global Revenue",
                                                     "Times New Roman Bold Italic", 18);
            title.setMargin2(0, 0, 6, 6);

            // Add a separator line just under the title
            c.addLine(10, title.getHeight(), c.getWidth() - 11, title.getHeight(), Chart.LineColor);

            // Add a legend box where the top-center is anchored to the horizontal center of the
            // chart, just under the title. Use horizontal layout and 10 points Arial Bold font, and
            // transparent background and border.
            LegendBox legendBox = c.addLegend(c.getWidth() / 2, title.getHeight(), false,
                                              "Arial Bold", 10);

            legendBox.setAlignment(Chart.TopCenter);
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);

            // Tentatively set the plotarea at (70, 75) and of 460 x 240 pixels in size. Use
            // transparent border and black (000000) grid lines
            c.setPlotArea(70, 75, 460, 240, -1, -1, Chart.Transparent, 0x000000, -1);

            // Set the x axis labels
            c.xAxis().setLabels(labels);

            // Show the same scale on the left and right y-axes
            c.syncYAxis();

            // Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will use this as the
            // guideline when putting ticks on the y-axis.
            c.yAxis().setTickDensity(30);

            // Set all axes to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);
            c.yAxis2().setColors(Chart.Transparent);

            // Set the x-axis margins to 15 pixels, so that the horizontal grid lines can extend
            // beyond the leftmost and rightmost vertical grid lines
            c.xAxis().setMargin(15, 15);

            // Set axis label style to 8pt Arial Bold
            c.xAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis2().setLabelStyle("Arial Bold", 8);

            // Add axis title using 10pt Arial Bold Italic font
            c.yAxis().setTitle("Revenue in USD millions", "Arial Bold Italic", 10);
            c.yAxis2().setTitle("Revenue in USD millions", "Arial Bold Italic", 10);

            // Add the first line. The missing data will be represented as gaps in the line (the
            // default behaviour)
            LineLayer layer0 = c.addLineLayer2();

            layer0.addDataSet(data0, 0xff0000, "Quantum Computer").setDataSymbol(
                Chart.GlassSphere2Shape, 11);
            layer0.setLineWidth(3);

            // Add the second line. The missing data will be represented by using dash lines to
            // bridge the gap
            LineLayer layer1 = c.addLineLayer2();

            layer1.addDataSet(data1, 0x00ff00, "Atom Synthesizer").setDataSymbol(
                Chart.GlassSphere2Shape, 11);
            layer1.setLineWidth(3);
            layer1.setGapColor(c.dashLineColor(0x00ff00));

            // Add the third line. The missing data will be ignored - just join the gap with the
            // original line style.
            LineLayer layer2 = c.addLineLayer2();

            layer2.addDataSet(data2, 0xff6600, "Proton Cannon").setDataSymbol(
                Chart.GlassSphere2Shape, 11);
            layer2.setLineWidth(3);
            layer2.setGapColor(Chart.SameAsMainColor);

            // layout the legend so we can get the height of the legend box
            c.layoutLegend();

            // Adjust the plot area size, such that the bounding box (inclusive of axes) is 15
            // pixels from the left edge, just under the legend box, 16 pixels from the right edge,
            // and 25 pixels from the bottom edge.
            c.packPlotArea(15, legendBox.getTopY() + legendBox.getHeight(), c.getWidth() - 16,
                           c.getHeight() - 25);

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Revenue of {dataSetName} in {xLabel}: US$ {value}M'");
        }
Exemple #8
0
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // The data for the line chart
            double[] data0  = { 42, 49, 33, 38, 64, 56, 29, 41, 44, 57, 59, 42 };
            double[] data1  = { 65, 75, 47, 34, 42, 49, 73, 62, 90, 69, 66, 78 };
            double[] data2  = { 36, 28, 25, 28, 38, 20, 22, 30, 25, 33, 30, 24 };
            string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
                                "Aug", "Sep", "Oct", "Nov", "Dec" };

            // Create a XYChart object of size 600 x 400 pixels
            XYChart c = new XYChart(600, 400);

            // Add a title to the chart using 18 pts Times Bold Italic font
            ChartDirector.TextBox title = c.addTitle("Product Line Global Revenue",
                                                     "Times New Roman Bold Italic", 18);

            // Tentatively set the plotarea at (50, 55) and of (chart_width - 100) x
            // (chart_height - 120) pixels in size. Use a vertical gradient color
            // from sky blue (aaccff) t0 light blue (f9f9ff) as background. Set both
            // horizontal and vertical grid lines to dotted semi-transprent black
            // (aa000000).
            PlotArea plotArea = c.setPlotArea(50, 55, c.getWidth() - 100,
                                              c.getHeight() - 120, c.linearGradientColor(0, 55, 0, 55 +
                                                                                         c.getHeight() - 120, 0xaaccff, 0xf9fcff), -1, -1, c.dashLineColor(
                                                  unchecked ((int)0xaa000000), Chart.DotLine), -1);

            // Add a legend box and anchored the top center at the horizontal center
            // of the chart, just under the title. Use 10pts Arial Bold as font, with
            // transparent background and border.
            LegendBox legendBox = c.addLegend(c.getWidth() / 2, title.getHeight(),
                                              false, "Arial Bold", 10);

            legendBox.setAlignment(Chart.TopCenter);
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);

            // Set y-axis title using 10 points Arial Bold Italic font, label style
            // to 8 points Arial Bold, and axis color to transparent
            c.yAxis().setTitle("Revenue (USD millions)", "Arial Bold Italic", 10);
            c.yAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis().setColors(Chart.Transparent);

            // Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will
            // use this as the guideline when putting ticks on the y-axis.
            c.yAxis().setTickDensity(30);

            // Add a line layer to the chart
            LineLayer layer = c.addLineLayer2();

            // Set the line width to 3 pixels
            layer.setLineWidth(3);

            // Add the three data sets to the line layer, using circles, diamands and
            // X shapes as symbols
            layer.addDataSet(data0, 0xff0000, "Quantum Computer").setDataSymbol(
                Chart.CircleSymbol, 9);
            layer.addDataSet(data1, 0x00ff00, "Atom Synthesizer").setDataSymbol(
                Chart.DiamondSymbol, 11);
            layer.addDataSet(data2, 0xff6600, "Proton Cannon").setDataSymbol(
                Chart.Cross2Shape(), 11);

            // Set the x axis labels
            c.xAxis().setLabels(labels);

            // Convert the labels on the x-axis to a CDMLTable
            CDMLTable table = c.xAxis().makeLabelTable();

            // Set the default top/bottom margins of the cells to 3 pixels
            table.getStyle().setMargin2(0, 0, 3, 3);

            // Use Arial Bold as the font for the first row
            table.getRowStyle(0).setFontStyle("Arial Bold");

            //
            // We can add more information to the table. In this sample code, we add
            // the data series and the legend icons to the table.
            //

            // Add 3 more rows to the table. Set the background of the 1st and 3rd
            // rows to light grey (eeeeee).
            table.appendRow().setBackground(0xeeeeee, Chart.LineColor);
            table.appendRow();
            table.appendRow().setBackground(0xeeeeee, Chart.LineColor);

            // Put the values of the 3 data series to the cells in the 3 rows
            for (int i = 0; i < data0.Length; ++i)
            {
                table.setText(i, 1, (data0[i]).ToString());
                table.setText(i, 2, (data1[i]).ToString());
                table.setText(i, 3, (data2[i]).ToString());
            }

            // Insert a column on the left for the legend icons. Use 5 pixels
            // left/right margins and 3 pixels top/bottom margins for the cells in
            // this column.
            table.insertCol(0).setMargin2(5, 5, 3, 3);

            // The top cell is set to transparent, so it is invisible
            table.getCell(0, 0).setBackground(Chart.Transparent, Chart.Transparent);

            // The other 3 cells are set to the legend icons of the 3 data series
            table.setText(0, 1, layer.getLegendIcon(0));
            table.setText(0, 2, layer.getLegendIcon(1));
            table.setText(0, 3, layer.getLegendIcon(2));

            // Layout legend box first, so we can get its size
            c.layoutLegend();

            // Adjust the plot area size, such that the bounding box (inclusive of
            // axes) is 2 pixels from the left, right and bottom edge, and is just
            // under the legend box.
            c.packPlotArea(2, legendBox.getTopY() + legendBox.getHeight(),
                           c.getWidth() - 3, c.getHeight() - 3);

            // After determining the exact plot area position, we may adjust the
            // legend box and the title positions so that they are centered relative
            // to the plot area (instead of the chart)
            legendBox.setPos(plotArea.getLeftX() + (plotArea.getWidth() -
                                                    legendBox.getWidth()) / 2, legendBox.getTopY());
            title.setPos(plotArea.getLeftX() + (plotArea.getWidth() - title.getWidth(
                                                    )) / 2, title.getTopY());

            // Output the chart
            viewer.Image = c.makeImage();

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Revenue of {dataSetName} in {xLabel}: US$ {value}M'");
        }
        private static XYChart GetChart(int width, int height, string xTitle, string yTitle, int fontSize,
                                        Dictionary <string, LineChartInfo> lineInfos, List <LineChartPoint> points)
        {
            //Chart.setLicenseCode("XXXXX");

            XYChart c = new XYChart(width, height);

            List <string> labels = new List <string>();

            foreach (LineChartPoint point in points)
            {
                labels.Add(point.XValue.ToString());
            }

            var labelStep = 2;

            while (Math.Round(labels.Count / (double)labelStep) > 10)
            {
                labelStep = labelStep * 5;
            }

            c.xAxis().setLabels(labels.ToArray());
            c.xAxis().setLabelStep(labelStep);

            List <string> lineNames = lineInfos.Keys.ToList();

            foreach (string lineName in lineNames)
            {
                LineChartInfo lineInfo = lineInfos[lineName];

                LineLayer layer = c.addLineLayer2();
                layer.setLineWidth(lineInfo.LineWidth);

                List <double> yValues = points.ConvertAll(o => o.YValues[lineName]);
                int           color   = lineInfo.Color;

                DataSet ds;

                if (lineInfo.LineStyle == LineStyle.Continuous)
                {
                    ds = layer.addDataSet(yValues.ToArray(), color, lineName);
                }
                else
                {
                    ds = layer.addDataSet(yValues.ToArray(), c.dashLineColor(color, Chart.DashLine), lineName);
                }

                if (!lineInfo.IsSpecialStar)
                {
                    ds.setDataSymbol(lineInfo.Symbol, lineInfo.SymbolSize, lineInfo.Color);
                }
                else
                {
                    ds.setDataSymbol(GetStar(), lineInfo.SymbolSize, lineInfo.Color, lineInfo.Color);
                }
            }

            ChartDirector.TextBox tbXTitle = c.xAxis().setTitle(xTitle, "", fontSize);
            ChartDirector.TextBox tbYTitle = c.yAxis().setTitle(yTitle, "", fontSize);

            //c.xAxis().setLinearScale(minX, maxX);
            //GenericMethods.SetRangeY(c, maxY, minY);
            SetFontSize(c, fontSize);
            SetOptions(c, width, height, fontSize, 20 + tbXTitle.getHeight(), 10 + tbYTitle.getHeight());

            return(c);
        }
Exemple #10
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the chart
            double[]   dataY = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1 };
            DateTime[] dataX = { new DateTime(2008,                                                 7, 1,  0,  0,  0), new DateTime(2008,                 7, 1,  2, 17, 2
                                                                                                                                    ), new DateTime(2008, 7,  1,  8,   5,               30), new DateTime(2008, 7,  1, 10,  54, 10),
                                 new DateTime(2008,                                                 7, 1, 15, 40,  0), new DateTime(2008,                 7, 1, 18, 22, 20),
                                 new DateTime(2008,                                                 7, 1, 22, 17, 14), new DateTime(2008,                 7, 2,  2, 55, 50),
                                 new DateTime(2008,                                                 7, 2,  8, 17, 14), new DateTime(2008,                 7, 2, 11, 55, 50),
                                 new DateTime(2008,                                                 7, 2, 13, 17, 14), new DateTime(2008,                 7, 2, 17, 55, 50),
                                 new DateTime(2008,                                                 7, 2, 20, 17, 14), new DateTime(2008,                 7, 3,  0,  0, 0) };

            // In this example, we only use position 1, 3, 5 for the data series. Positions 0, 2, 4,
            // 6 are empty and serve as gaps.
            string[] labels = { "",                                                                             "ON Only Filling", "",
                                "<*font,color=cc2200*>ON<*/font*> / <*font,color=00aa22*>OFF<*/font*> Filling", "",
                                "Logic Line",                                                                   "" };

            // Create a XYChart object of size 600 x 180 pixels
            XYChart c = new XYChart(600, 180);

            // Add a title to the chart using 10 points Arial Bold font. Set top/bottom margins to
            // 12 pixels.
            ChartDirector.TextBox title = c.addTitle("Binary Data Series Demonstration",
                                                     "Arial Bold", 10);

            // Tentatively set the plotarea at (100, 30) and of size 470 x 120 pixels. Use
            // transparent border. Use grey (888888) solid line and light grey (ccccc) dotted line
            // as major and minor vertical grid lines.
            c.setPlotArea(100, 30, 470, 120, -1, -1, Chart.Transparent).setGridColor(
                Chart.Transparent, 0x888888, Chart.Transparent, c.dashLineColor(0xcccccc,
                                                                                Chart.DotLine));

            // Set axes to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);

            // Set the y axis labels
            c.yAxis().setLabels(labels);

            // Set y-axis label style to 8pt Arial Bold
            c.yAxis().setLabelStyle("Arial Bold", 8);

            // Set x-axis major and minor tick density to 50 and 5 pixels. ChartDirector
            // auto-scaling will use this as the guideline when putting ticks on the x-axis.
            c.xAxis().setTickDensity(50, 5);

            // Use "<*font=Arial Bold*>{value|mmm dd}" for the first label of an hour, and
            // "{value|hh:nn}" for all other labels.
            c.xAxis().setMultiFormat(Chart.StartOfDayFilter(), "<*font=Arial Bold*>{value|mmm dd}",
                                     Chart.AllPassFilter(), "{value|hh:nn}");

            //
            // A Logic Line can be achieved using a StepLineLayer in ChartDirector
            //

            // Shift the data by 4.5, so instead of 0 - 1, it is now 4.5 to 5.5, or fluctuate around
            // the y = 5 (Logic Line label) position.
            double[] shiftedLine0 = new ArrayMath(dataY).add(4.5).result();

            // Add step lines using the original and the reversed data
            StepLineLayer layer0 = c.addStepLineLayer(shiftedLine0, 0x0000ff);

            layer0.setXData(dataX);

            //
            // To perform ON/OFF filling, we draw the logic line, and its reverse, and fill the
            // region in between
            //

            // Shift the data by 2.5, so instead of 0 - 1, it is now 2.5 to 3.5, or fluctuate around
            // the y = 3 (ON/OFF Filing label) position.
            double[] shiftedLine1 = new ArrayMath(dataY).add(2.5).result();
            // Reverse the data, so the 0 becomes 1 and 1 becomes 0, and shift it as well.
            double[] reverseShiftedLine1 = new ArrayMath(dataY).mul(-1).add(3.5).result();

            // Add step lines using the original and the reversed data
            StepLineLayer layer1 = c.addStepLineLayer(shiftedLine1, Chart.Transparent);

            layer1.addDataSet(reverseShiftedLine1, Chart.Transparent);
            layer1.setXData(dataX);

            // Fill the region between the two step lines with green (00aa22) or red (cc2200),
            // depending on whether the original or the reserve is higher.
            c.addInterLineLayer(layer1.getLine(0), layer1.getLine(1), 0x00aa22, 0xcc2200);

            //
            // The ON Only filling is the same as ON/OFF filling, except the OFF filling color is
            // transparent
            //

            // Shift the data by 0.5, so instead of 0 - 1, it is now 0.5 to 1.5, or fluctuate around
            // the y = 1 (ON Only Filing label) position.
            double[] shiftedLine2 = new ArrayMath(dataY).add(0.5).result();
            // Reverse the data, so the 0 becomes 1 and 1 becomes 0, and shift it as well.
            double[] reverseShiftedLine2 = new ArrayMath(dataY).mul(-1).add(1.5).result();

            // Add step lines using the original and the reversed data
            StepLineLayer layer2 = c.addStepLineLayer(shiftedLine2, Chart.Transparent);

            layer2.addDataSet(reverseShiftedLine2, Chart.Transparent);
            layer2.setXData(dataX);

            // Fill the region between the two step lines with green (00aa22) or transparent,
            // depending on whether the original or the reserve is higher.
            c.addInterLineLayer(layer2.getLine(0), layer2.getLine(1), 0x00aa22, Chart.Transparent);

            // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10
            // pixels from the left edge, 10 pixels  below the title, 30 pixels from the right edge,
            // and 10 pixels above the bottom edge.
            c.packPlotArea(10, title.getHeight() + 10, c.getWidth() - 30, c.getHeight() - 10);

            // Output the chart
            viewer.Chart = c;
        }
Exemple #11
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // The data for the chart
            double[] data = { 40, 15, 7, 5, 2 };

            // The labels for the chart
            string[] labels = { "Hard Disk", "PCB", "Printer", "CDROM", "Keyboard" };

            // In the pareto chart, the line data are just the accumulation of the raw data, scaled to a
            // range of 0 - 100%
            ArrayMath lineData = new ArrayMath(data);

            lineData.acc();
            double scaleFactor = lineData.max() / 100;

            if (scaleFactor == 0)
            {
                // Avoid division by zero error for zero data
                scaleFactor = 1;
            }
            lineData.div2(scaleFactor);

            // Create a XYChart object of size 480 x 300 pixels. Set background color to brushed silver,
            // with a grey (bbbbbb) border and 2 pixel 3D raised effect. Use rounded corners. Enable soft
            // drop shadow.
            XYChart c = new XYChart(400, 300, Chart.brushedSilverColor(), 0xbbbbbb, 2);

            c.setRoundedFrame();
            c.setDropShadow();

            // Add a title to the chart using 15 points Arial Italic. Set top/bottom margins to 12
            // pixels.
            ChartDirector.TextBox title = c.addTitle("Pareto Chart Demonstration", "Arial Italic", 15);
            title.setMargin2(0, 0, 12, 12);

            // Tentatively set the plotarea at (50, 40). Set the width to 100 pixels less than the chart
            // width, and the height to 80 pixels less than the chart height. Use pale grey (f4f4f4)
            // background, transparent border, and dark grey (444444) dotted grid lines.
            c.setPlotArea(50, 40, c.getWidth() - 100, c.getHeight() - 80, 0xf4f4f4, -1,
                          Chart.Transparent, c.dashLineColor(0x444444, Chart.DotLine));

            // Add a line layer for the pareto line
            LineLayer lineLayer = c.addLineLayer2();

            // Add the pareto line using deep blue (0000ff) as the color, with circle symbols
            lineLayer.addDataSet(lineData.result(), 0x0000ff).setDataSymbol(Chart.CircleShape, 9,
                                                                            0x0000ff, 0x0000ff);

            // Set the line width to 2 pixel
            lineLayer.setLineWidth(2);

            // Bind the line layer to the secondary (right) y-axis.
            lineLayer.setUseYAxis2();

            // Tool tip for the line layer
            lineLayer.setHTMLImageMap("", "", "title='Top {={x}+1} items: {value|2}%'");

            // Add a multi-color bar layer using the given data.
            BarLayer barLayer = c.addBarLayer3(data);

            // Set soft lighting for the bars with light direction from the right
            barLayer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Right));

            // Tool tip for the bar layer
            barLayer.setHTMLImageMap("", "", "title='{xLabel}: {value} pieces'");

            // Set the labels on the x axis.
            c.xAxis().setLabels(labels);

            // Set the secondary (right) y-axis scale as 0 - 100 with a tick every 20 units
            c.yAxis2().setLinearScale(0, 100, 20);

            // Set the format of the secondary (right) y-axis label to include a percentage sign
            c.yAxis2().setLabelFormat("{value}%");

            // Set the relationship between the two y-axes, which only differ by a scaling factor
            c.yAxis().syncAxis(c.yAxis2(), scaleFactor);

            // Set the format of the primary y-axis label foramt to show no decimal point
            c.yAxis().setLabelFormat("{value|0}");

            // Add a title to the primary y-axis
            c.yAxis().setTitle("Frequency");

            // Set all axes to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);
            c.yAxis2().setColors(Chart.Transparent);

            // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10 pixels
            // from the left edge, just below the title, 10 pixels from the right edge, and 20 pixels
            // from the bottom edge.
            c.packPlotArea(10, title.getHeight(), c.getWidth() - 10, c.getHeight() - 20);

            // Output the chart
            viewer.Image = c.makeWebImage(Chart.JPG);

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("");
        }
Exemple #12
0
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // The x and y coordinates of the grid
            double[] dataX = { -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4,
                               5,    6,  7,  8,  9, 10 };
            double[] dataY = { -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4,
                               5,    6,  7,  8,  9, 10 };

            // The values at the grid points. In this example, we will compute the
            // values using the formula z = x * sin(y) + y * sin(x).
            double[] dataZ = new double[(dataX.Length) * (dataY.Length)];
            for (int yIndex = 0; yIndex < dataY.Length; ++yIndex)
            {
                double y = dataY[yIndex];
                for (int xIndex = 0; xIndex < dataX.Length; ++xIndex)
                {
                    double x = dataX[xIndex];
                    dataZ[yIndex * (dataX.Length) + xIndex] = x * Math.Sin(y) + y *
                                                              Math.Sin(x);
                }
            }

            // Create a XYChart object of size 600 x 500 pixels
            XYChart c = new XYChart(600, 500);

            // Add a title to the chart using 15 points Arial Bold Italic font
            c.addTitle("z = x * sin(y) + y * sin(x)      ", "Arial Bold Italic", 15);

            // Set the plotarea at (75, 40) and of size 400 x 400 pixels. Use
            // semi-transparent black (80000000) dotted lines for both horizontal and
            // vertical grid lines
            c.setPlotArea(75, 40, 400, 400, -1, -1, -1, c.dashLineColor(
                              unchecked ((int)0x80000000), Chart.DotLine), -1);

            // Set x-axis and y-axis title using 12 points Arial Bold Italic font
            c.xAxis().setTitle("X-Axis Title Place Holder", "Arial Bold Italic", 12);
            c.yAxis().setTitle("Y-Axis Title Place Holder", "Arial Bold Italic", 12);

            // Set x-axis and y-axis labels to use Arial Bold font
            c.xAxis().setLabelStyle("Arial Bold");
            c.yAxis().setLabelStyle("Arial Bold");

            // When auto-scaling, use tick spacing of 40 pixels as a guideline
            c.yAxis().setTickDensity(40);
            c.xAxis().setTickDensity(40);

            // Add a contour layer using the given data
            ContourLayer layer = c.addContourLayer(dataX, dataY, dataZ);

            // Move the grid lines in front of the contour layer
            c.getPlotArea().moveGridBefore(layer);

            // Add a color axis (the legend) in which the top left corner is anchored
            // at (505, 40). Set the length to 400 pixels and the labels on the right
            // side.
            ColorAxis cAxis = layer.setColorAxis(505, 40, Chart.TopLeft, 400,
                                                 Chart.Right);

            // Add a title to the color axis using 12 points Arial Bold Italic font
            cAxis.setTitle("Color Legend Title Place Holder", "Arial Bold Italic", 12
                           );

            // Set color axis labels to use Arial Bold font
            cAxis.setLabelStyle("Arial Bold");

            // Output the chart
            viewer.Image = c.makeImage();
        }
Exemple #13
0
        /// <summary>
        /// 绘制噪声数据比较分析图
        /// </summary>
        private void CreateChart(int line)
        {
            if (sRecorder == null)
            {
                return;
            }

            XYChart c = new XYChart(700, 360);

            c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888);

            ChartDirector.TextBox title = c.addTitle("噪声数据比较分析图", "Arial Bold", 13);
            title.setPos(0, 20);

            c.setPlotArea(80, 80, 580, 230, 0xffffff, -1, -1, c.dashLineColor(
                              0xaaaaaa, Chart.DotLine), -1);

            LegendBox legendBox = c.addLegend(350, 80, false, "Arial", 8);

            legendBox.setAlignment(Chart.BottomCenter);
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);
            legendBox.setLineStyleKey();
            legendBox.setFontSize(8);

            c.xAxis().setIndent(true);
            c.xAxis().setTitle("噪声频率(Hz)");


            c.yAxis().setTitle("噪声幅度(%)");


            LineLayer layer1;

            ChartDirector.DataSet ds;
            double[] dataSet;
            double[] da;

            dataSet = sRecorder.Data.Amplitude.Skip(4).ToArray();
            da      = sRecorder.Data.Frequency.Skip(4).ToArray();
            switch (line)
            {
            case 0:
                layer1 = c.addLineLayer();
                ds     = layer1.addDataSet(dataSet, GetRandomColor(0), "记录仪" + sRecorder.ID);
                layer1.setLineWidth(2);
                layer1.setXData(da);
                break;

            case 1:
                layer1 = c.addSplineLayer();
                ds     = layer1.addDataSet(dataSet, GetRandomColor(0), "记录仪" + sRecorder.ID);
                layer1.setLineWidth(2);
                layer1.setXData(da);
                break;
            }

            if (eRecorder != null && sRecorder.ID != eRecorder.ID)
            {
                dataSet = eRecorder.Data.Amplitude.Skip(4).ToArray();
                da      = eRecorder.Data.Frequency.Skip(4).ToArray();
                switch (line)
                {
                case 0:
                    layer1 = c.addLineLayer();
                    ds     = layer1.addDataSet(dataSet, GetRandomColor(1), "记录仪" + eRecorder.ID);
                    layer1.setLineWidth(2);
                    layer1.setXData(da);
                    break;

                case 1:
                    layer1 = c.addSplineLayer();
                    ds     = layer1.addDataSet(dataSet, GetRandomColor(1), "记录仪" + eRecorder.ID);
                    layer1.setLineWidth(2);
                    layer1.setXData(da);
                    break;
                }
            }

            c.xAxis().setLabelStep(15);
            c.yAxis().setDateScale(0, 120);

            winChartViewer1.Chart    = c;
            winChartViewer1.ImageMap = c.getHTMLImageMap("clickable", "",
                                                         "title='噪声频率: {x}Hz, \n{dataSetName}: {value}%'");
        }
        private void createChart()
        {
            string[] xLabels = null;
            if (lst_data.Count != 0)
            {
                xLabels = new string[lst_data.Count];

                for (int i = 0; i < xLabels.Length; i++)
                {
                    xLabels[i] = (i + 1).ToString();
                }
            }

            XYChart chart = new XYChart(795, 455);//(857, 448);

            chart.setBackground(chart.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888);

            ChartDirector.TextBox title1_txt = chart.addTitle("能量强度变化分析", "Arial Bold", 13);
            title1_txt.setPos(0, 20);

            chart.setPlotArea(50, 60, 620, 340, 0xffffff, -1, -1, chart.dashLineColor(Chart.CColor(Color.AliceBlue), Chart.DotLine), -1);
            chart.xAxis().setLabels(xLabels);
            chart.xAxis().setLabelStep(1);
            chart.xAxis().setIndent(true);
            chart.xAxis().setTitle("点数");

            chart.yAxis().setTitle("噪声强度");

            LineLayer layer;

            layer = chart.addLineLayer();
            layer.addDataSet(lst_data.ToArray(), Chart.CColor(Color.Green), "噪声强度");
            layer.setLineWidth(2);
            layer.setFastLineMode(true);

            layer = chart.addLineLayer();
            layer.addDataSet(lst_stdev.ToArray(), Chart.CColor(Color.DarkViolet), "绝对差");
            layer.setLineWidth(2);
            layer.setFastLineMode(true);

            //标准平均值
            Mark standAMPmark = chart.yAxis().addMark(Standard_average, Chart.CColor(Color.Crimson), "", "Arial Bold");

            standAMPmark.setLineWidth(2);
            standAMPmark.setPos(-15, 10);
            standAMPmark.setFontAngle(90);

            //静态漏水标准幅度值
            Mark standAVmark = chart.yAxis().addMark(StandardAMP, Chart.CColor(Color.Cyan), "", "Arial Bold");

            standAVmark.setLineWidth(2);
            standAVmark.setPos(-15, 10);
            standAVmark.setFontAngle(90);

            Mark energymark = chart.yAxis().addMark(energyvalue, Chart.CColor(Color.Chartreuse), "", "Arial Bold");

            LegendBox legendbox = chart.addLegend(672, 60);

            legendbox.addKey("标准平均值", Chart.CColor(Color.Crimson));
            legendbox.addKey("静态漏水标准", Chart.CColor(Color.Cyan));
            legendbox.addKey("能量强度", Chart.CColor(Color.Chartreuse));
            //legendbox.addKey("噪声强度", Chart.CColor(Color.Green));
            //legendbox.addKey("绝对差", Chart.CColor(Color.DarkViolet));

            chart.layout();

            winChartViewer1.Chart    = chart;
            winChartViewer1.ImageMap =
                winChartViewer1.Chart.getHTMLImageMap("clickable", "", "title='点数: {xLabel},强度: {value}'");
        }
Exemple #15
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WPFChartViewer viewer, int chartIndex)
        {
            // The data for the line chart
            double[] data0  = { 410, 420, 500, 590 };
            double[] data1  = { 500, 370, 680, 850 };
            string[] labels = { "Q1", "Q2", "Q3", "Q4" };

            // Create a XYChart object of size 600 x 400 pixels
            XYChart c = new XYChart(600, 400);

            // Add a title to the chart using 18pt Times Bold Italic font
            ChartDirector.TextBox title = c.addTitle("Product Line Global Revenue",
                                                     "Times New Roman Bold Italic", 18);

            // Tentatively set the plotarea at (50, 55) and of (chart_width - 100) x (chart_height -
            // 150) pixels in size. Use a vertical gradient color from sky blue (aaccff) t0 light
            // blue (f9f9ff) as background. Set both horizontal and vertical grid lines to dotted
            // semi-transprent black (aa000000).
            PlotArea plotArea = c.setPlotArea(50, 55, c.getWidth() - 100, c.getHeight() - 150,
                                              c.linearGradientColor(0, 55, 0, 55 + c.getHeight() - 150, 0xaaccff, 0xf9fcff), -1,
                                              -1, c.dashLineColor(unchecked ((int)0xaa000000), Chart.DotLine), -1);

            // Set y-axis title using 12 points Arial Bold Italic font, and set its position 10
            // pixels from the axis.
            c.yAxis().setTitle("Revenue (USD millions)", "Arial Bold Italic", 12);
            c.yAxis().setTitlePos(Chart.Left, 10);

            // Set y-axis label style to 10 points Arial Bold and axis color to transparent
            c.yAxis().setLabelStyle("Arial Bold", 10);
            c.yAxis().setColors(Chart.Transparent);

            // Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will use this as the
            // guideline when putting ticks on the y-axis.
            c.yAxis().setTickDensity(30);

            // Add a bar layer to the chart with side layout
            BarLayer layer = c.addBarLayer2(Chart.Side);

            // Add two data sets to the bar layer
            layer.addDataSet(data0, 0xff6600, "FY 2007");
            layer.addDataSet(data1, 0x0088ff, "FY 2008");

            // Use soft lighting effect with light direction from the left
            layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Left));

            // Set the x axis labels
            c.xAxis().setLabels(labels);

            // Convert the labels on the x-axis to a CDMLTable
            CDMLTable table = c.xAxis().makeLabelTable();

            // Set the default left/right margins to 5 pixels and top/bottom margins to 3 pixels.
            // Set the default font size to 10 points
            ChartDirector.TextBox cellStyle = table.getStyle();
            cellStyle.setMargin2(5, 5, 4, 3);
            cellStyle.setFontSize(10);

            // Set the first row to use Arial Bold font, with a light grey (eeeeee) background.
            ChartDirector.TextBox firstRowStyle = table.getRowStyle(0);
            firstRowStyle.setFontStyle("Arial Bold");
            firstRowStyle.setBackground(0xeeeeee, Chart.LineColor);

            //
            // We can add more information to the table. In this sample code, we add the data series
            // and the legend icons to the table.
            //

            // Add 3 more rows to the table. Set the background of the 2nd row to light grey
            // (eeeeee).
            table.appendRow();
            table.appendRow().setBackground(0xeeeeee, Chart.LineColor);
            table.appendRow();

            // Put the values of the 2 data series in the first 2 rows. Put the percentage
            // differences in the 3rd row.
            for (int i = 0; i < data0.Length; ++i)
            {
                table.setText(i, 1, (data0[i]).ToString());
                table.setText(i, 2, (data1[i]).ToString());

                double percentageDiff = 100.0 * (data1[i] - data0[i]) / data0[i];

                // Use red or green color depending on whether the difference is positive or
                // negative
                string formatString = "<*color=008800*>+{value|1}%";
                if (percentageDiff < 0)
                {
                    formatString = "<*color=cc0000*>{value|1}%";
                }
                table.setText(i, 3, c.formatValue(percentageDiff, formatString));
            }

            // Insert a column on the left for the legend icons using Arial Bold font.
            table.insertCol(0).setFontStyle("Arial Bold");

            // The top cell is set to transparent, so it is invisible
            table.getCell(0, 0).setBackground(Chart.Transparent, Chart.Transparent);

            // The next 2 cells are set to the legend icons and names of the 2 data series
            table.setText(0, 1, layer.getLegendIcon(0) + "  FY 2007");
            table.setText(0, 2, layer.getLegendIcon(1) + "  FY 2008");

            // The last cell is set to "Change"
            table.setText(0, 3, "Change");

            // Append a column on the right for the total values.
            table.appendCol();

            // Put "Total" in the top cell as the heading of this column
            table.setText(table.getColCount() - 1, 0, "Total");

            // The next two cells are the total of the data series
            double total0 = new ArrayMath(data0).sum();
            double total1 = new ArrayMath(data1).sum();

            table.setText(table.getColCount() - 1, 1, (total0).ToString());
            table.setText(table.getColCount() - 1, 2, (total1).ToString());

            // The last cell is the percentage differences of the total
            double totalPercentageDiff = (total1 - total0) / total0 * 100;

            // Use red or green color depending on whether the difference is positive or negative
            string totalFormatString = "<*color=008800*>+{value|1}%";

            if (totalPercentageDiff < 0)
            {
                totalFormatString = "<*color=cc0000*>{value|1}%";
            }
            table.setText(table.getColCount() - 1, 3, c.formatValue(totalPercentageDiff,
                                                                    totalFormatString));

            //
            // We now demonstrate how to adjust the plot area positions, to allow space for the
            // newly inserted left and right columns in the table.
            //

            // We layout the axis first in order to get the axis metrics (including table metrics)
            c.layoutAxes();

            // If the first column is wider than the left y-axis, we need to reserve for some left
            // margin to ensure the first column stays within the chart.
            int leftMargin = 0;

            if (table.getColWidth(0) > c.yAxis().getThickness())
            {
                leftMargin = table.getColWidth(0) - c.yAxis().getThickness();
            }

            // Similarly, we need to reserve some right margin for the last column
            int rightMargin = table.getColWidth(table.getColCount() - 1);

            // Adjust the plot area size, such that the bounding box (inclusive of axes) using the
            // given left and right margin, plus 2 more pixels. Put the plot area 10 pixels below
            // the title and use 2 pixels as the bottom margin. from the left, right and bottom
            // edge, and is just under the legend box.
            c.packPlotArea(leftMargin + 2, title.getHeight() + 10, c.getWidth() - 3 - rightMargin,
                           c.getHeight() - 3);

            // After determining the exact plot area position, we may adjust title position so that
            // it is centered relative to the plot area (instead of the chart)
            title.setPos(plotArea.getLeftX() + (plotArea.getWidth() - title.getWidth()) / 2,
                         title.getTopY());

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Revenue in {xLabel} {dataSetName}: US$ {value}M'");
        }
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the chart
            double[] data = { 50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59,
                              73, 77, 84, 82, 80, 84, 89 };

            // The error data representing the error band around the data points
            double[] errData = { 5,     6, 5.1, 6.5, 6.6,    8,  5.4,  5.1,  4.6, 5.0, 5.2, 6.0, 4.9, 5.6, 4.8,
                                 6.2, 7.4, 7.1, 6.5, 9.6, 12.1, 15.3, 18.5, 20.9, 24.1 };

            // The timestamps for the data
            DateTime[] labels = { new DateTime(2001,                                                                                       1, 1), new DateTime(2001,                 2, 1), new DateTime(
                                      2001,                                                                                                3, 1), new DateTime(2001,                 4, 1), new DateTime(2001,                 5, 1), new DateTime(2001,
                                                                                                                                                                                                                                                   6,                    1), new DateTime(2001,  7,                1), new DateTime(2001,  8,                1),new DateTime(2001,9, 1),
                                  new DateTime(2001,                                                                                      10, 1), new DateTime(2001,                11, 1), new DateTime(2001,                12, 1),
                                  new DateTime(2002,                                                                                       1, 1), new DateTime(2002,                 2, 1), new DateTime(2002,                 3, 1),
                                  new DateTime(2002,                                                                                       4, 1), new DateTime(2002,                 5, 1), new DateTime(2002,                 6, 1),
                                  new DateTime(2002,                                                                                       7, 1), new DateTime(2002,                 8, 1), new DateTime(2002,                 9, 1),
                                  new DateTime(2002,                                                                                      10, 1), new DateTime(2002,                11, 1), new DateTime(2002,                12, 1),
                                  new DateTime(2003,                                                                                       1, 1) };

            // Create a XYChart object of size 550 x 220 pixels
            XYChart c = new XYChart(550, 220);

            // Set the plot area at (50, 10) and of size 480 x 180 pixels. Enabled both vertical and
            // horizontal grids by setting their colors to light grey (cccccc)
            c.setPlotArea(50, 10, 480, 180).setGridColor(0xcccccc, 0xcccccc);

            // Add a legend box (50, 10) (top of plot area) using horizontal layout. Use 8pt Arial
            // font. Disable bounding box (set border to transparent).
            LegendBox legendBox = c.addLegend(50, 10, false, "", 8);

            legendBox.setBackground(Chart.Transparent);

            // Add keys to the legend box to explain the color zones
            legendBox.addKey("Historical", 0x9999ff);
            legendBox.addKey("Forecast", 0xff9966);

            // Add a title to the y axis.
            c.yAxis().setTitle("Energy Consumption");

            // Set the labels on the x axis
            c.xAxis().setLabels2(labels);

            // Set multi-style axis label formatting. Use Arial Bold font for yearly labels and
            // display them as "yyyy". Use default font for monthly labels and display them as
            // "mmm". Replace some labels with minor ticks to ensure the labels are at least 3 units
            // apart.
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "<*font=Arial Bold*>{value|yyyy}",
                                     Chart.StartOfMonthFilter(), "{value|mmm}", 3);

            // Add a line layer to the chart
            LineLayer layer = c.addLineLayer2();

            // Create the color to draw the data line. The line is blue (0x333399) to the left of x
            // = 18, and become a red (0xd04040) dash line to the right of x = 18.
            int lineColor = layer.xZoneColor(18, 0x333399, c.dashLineColor(0xd04040, Chart.DashLine)
                                             );

            // Add the data line
            layer.addDataSet(data, lineColor, "Average");

            // We are not showing the data set name in the legend box. The name is for showing in
            // tool tips only.
            layer.setLegend(Chart.NoLegend);

            // Create the color to draw the err zone. The color is semi-transparent blue
            // (0x809999ff) to the left of x = 18, and become semi-transparent red (0x80ff9966) to
            // the right of x = 18.
            int errColor = layer.xZoneColor(18, unchecked ((int)0x809999ff),
                                            unchecked ((int)0x80ff9966));

            // Add the upper border of the err zone
            layer.addDataSet(new ArrayMath(data).add(errData).result(), errColor, "Upper bound");

            // Add the lower border of the err zone
            layer.addDataSet(new ArrayMath(data).sub(errData).result(), errColor, "Lower bound");

            // Set the default line width to 2 pixels
            layer.setLineWidth(2);

            // In this example, we are not showing the data set name in the legend box
            layer.setLegend(Chart.NoLegend);

            // Color the region between the err zone lines
            c.addInterLineLayer(layer.getLine(1), layer.getLine(2), errColor);

            // Output the chart
            viewer.Chart = c;

            // Include tool tip for the chart.
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} on {xLabel|mmm yyyy}: {value} MJoule'");
        }
Exemple #17
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the line chart
            double[] data0 = { 70, 73, 80, 90, 95, 93, 82, 77, 82, 101, 111, 115 };
            double[] data1 = { 90, 96, 89, 77, 82, 96, 109, 109, 99, 108, 96, 91 };
            double[] data2 = { 58, 34, 25, 49, 64, 10, 16, 40, 25, 49, 40, 22 };

            // The labels for the line chart
            string[] labels = { "2008-01", "2008-02", "2008-03", "2008-04", "2008-05", "2008-06",
                                "2008-07", "2008-08", "2008-09", "2008-10", "2008-11", "2008-12" };

            // Create a XYChart object of size 450 x 450 pixels
            XYChart c = new XYChart(450, 450);

            // Add a title to the chart using 15pt Arial Italic font.
            ChartDirector.TextBox title = c.addTitle("Inter-line Coloring", "Arial Italic", 15);

            // Add a legend box where the top-center is anchored to the horizontal center of the
            // chart, just under the title. Use horizontal layout and 10 points Arial Bold font, and
            // transparent background and border. Use line style legend key.
            LegendBox legendBox = c.addLegend(c.getWidth() / 2, title.getHeight(), false,
                                              "Arial Bold Italic", 10);

            legendBox.setBackground(Chart.Transparent, Chart.Transparent);
            legendBox.setAlignment(Chart.TopCenter);
            legendBox.setLineStyleKey();

            // Tentatively set the plotarea at (70, 65) and of (chart_width - 100) x (chart_height -
            // 110) in size. Use light grey (c0c0c0) border and horizontal and vertical grid lines.
            PlotArea plotArea = c.setPlotArea(70, 65, c.getWidth() - 100, c.getHeight() - 110, -1,
                                              -1, 0xc0c0c0, 0xc0c0c0, -1);

            // Add a title to the y axis using 12pt Arial Bold Italic font
            c.yAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12);

            // Add a title to the x axis using 12pt Arial Bold Italic font
            c.xAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12);

            // Set the axes line width to 3 pixels
            c.xAxis().setWidth(3);
            c.yAxis().setWidth(3);

            // Set the labels on the x axis.
            c.xAxis().setLabels(labels);

            // Use 8 points Arial rotated by 90 degrees as the x-axis label font
            c.xAxis().setLabelStyle("Arial", 8, Chart.TextColor, 90);

            // Add a spline curve to the chart
            SplineLayer layer0 = c.addSplineLayer(data0, 0xff0000, "Data Set 0");

            layer0.setLineWidth(2);

            // Add a normal line to the chart
            LineLayer layer1 = c.addLineLayer(data1, 0x008800, "Data Set 1");

            layer1.setLineWidth(2);

            // Color the region between the above spline curve and normal line. Use the
            // semi-transparent red (80ff000000) if the spline curve is higher than the normal line,
            // otherwise use semi-transparent green (80008800)
            c.addInterLineLayer(layer0.getLine(), layer1.getLine(), unchecked ((int)0x80ff0000),
                                unchecked ((int)0x80008800));

            // Add another normal line to the chart
            LineLayer layer2 = c.addLineLayer(data2, 0x0000ff, "Data Set 2");

            layer2.setLineWidth(2);

            // Add a horizontal mark line to the chart at y = 40
            Mark mark = c.yAxis().addMark(40, -1, "Threshold");

            mark.setLineWidth(2);

            // Set the mark line to purple (880088) dash line. Use white (ffffff) for the mark
            // label.
            mark.setMarkColor(c.dashLineColor(0x880088), 0xffffff);

            // Put the mark label at the left side of the mark, with a purple (880088) background.
            mark.setAlignment(Chart.Left);
            mark.setBackground(0x880088);

            // Color the region between the above normal line and mark line. Use the
            // semi-transparent blue (800000ff) if the normal line is higher than the mark line,
            // otherwise use semi-transparent purple (80880088)
            c.addInterLineLayer(layer2.getLine(), mark.getLine(), unchecked ((int)0x800000ff),
                                unchecked ((int)0x80880088));

            // Layout the legend box, so we can get its height
            c.layoutLegend();

            // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10
            // pixels from the left edge, just under the legend box, 25 pixels from the right edge,
            // and 10 pixels from the bottom edge.
            c.packPlotArea(10, legendBox.getTopY() + legendBox.getHeight(), c.getWidth() - 25,
                           c.getHeight() - 10);

            // After determining the exact plot area position, we may adjust the legend box and the
            // title positions so that they are centered relative to the plot area (instead of the
            // chart)
            legendBox.setPos(plotArea.getLeftX() + (plotArea.getWidth() - legendBox.getWidth()) / 2,
                             legendBox.getTopY());
            title.setPos(plotArea.getLeftX() + (plotArea.getWidth() - title.getWidth()) / 2,
                         title.getTopY());

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} in {xLabel}: {value}'");
        }
        private void UpdatePlot(object sender, RunWorkerCompletedEventArgs e)
        {
            List<object> objlist = new List<object>();
            objlist.AddRange((List<object>)e.Result);
            double[] depart = (double[])objlist[0];
            double[] arrive = (double[])objlist[1];
            double[] departVel = (double[])objlist[2];
            string Plan1Name = (string)objlist[3];
            string Plan2Name = (string)objlist[4];

            XYChart c = new XYChart(800, 800);
            c.setPlotArea(75, 40, 600, 600, -1, -1, -1, c.dashLineColor(unchecked((int)0x80000000), Chart.DotLine), -1);
            // When auto-scaling, use tick spacing of 40 pixels as a guideline
            c.yAxis().setTickDensity(40);
            c.xAxis().setTickDensity(40);


            // Add a contour layer using the given data
            ContourLayer layer = c.addContourLayer(depart, arrive, departVel);
            c.getPlotArea().moveGridBefore(layer);
            ColorAxis cAxis = layer.setColorAxis(700, 40, Chart.TopLeft, 400, Chart.Right);
            double[] colorScale = { 3, 0x090446, 3.3, 0x16366B, 3.6, 0x236890, 3.9, 0x309AB5, 4.2, 0x53C45A, 4.5, 0x77EF00, 4.8, 0xBBF70F, 5.1, 0xFFFF1E, 5.4, 0xFF8111, 5.7, 0xFF0404 };
            cAxis.setColorScale(colorScale, 0x090446, 0xffffff);
            cAxis.setColorGradient(false);
            // Add a title to the color axis using 12 points Arial Bold Italic font
            cAxis.setTitle("Departure Velocity (km/s)", "Arial Bold Italic", 12);
            c.xAxis().setTitle("Departure Date (JDCT)");
            c.yAxis().setTitle("Arrival Date (JDCT)");
            c.addTitle("Departure Velocity from " + Plan1Name + " to " + Plan2Name);
            c.xAxis().setTickLength(10);
            c.yAxis().setTickLength(10);


            // Output the chart
            winChartViewer1.Chart = c;
            winChartViewer1.ImageMap = c.getHTMLImageMap("");
            /*
                        // The data for the bar chart
            double[] data = {85, 156, 179.5, 211, 123};

            // The labels for the bar chart
            string[] labels = { "Mon", "Tue", "Wed", "Thu", "Fri" };

            XYChart c = new XYChart(250, 250);
            c.setPlotArea(30, 20, 200, 200);
            c.addBarLayer(data);
            c.xAxis().setLabels(labels);
            winChartViewer1.Chart = c;
            */

        }
        public void createChartCenter(WinChartViewer viewer, string img)
        {
            // The data for the chart
            //double[] data0;
            //double[] data1;
            //double[] data2;
            //double[] data3;
            //string[] labels;
            //int idate;
            ////double[] data0 = { 185, 176, 135, 144,99, 120, 175, 128, 175, 142, 172, 120, 175, 123, 120, 185, 145, 185, 152, 142, 156, 156, 175, 185, 175, 148, 142 };
            ////double[] data1 = { 145, 153, 123, 175, 120, 105, 142, 147, 145, 184, 124, 132, 102, 125, 165, 156, 125, 156, 125, 143, 142, 148, 129, 145, 169, 136, 187 };
            ////double[] data2 = { 135, 120, 145, 126, 100, 145, 120, 120, 156, 129, 168, 185, 165, 135, 158, 125, 126, 125, 163, 165, 132, 143, 138, 136, 185, 159, 144 };
            ////double[] data3 = { 150, 110, 187, 173, 85, 100, 135, 156, 155, 120, 127, 122, 125, 145, 134, 185, 132, 185, 128, 123, 185, 129, 136, 162, 125, 189, 165 };
            //if (_dt_grid != null && _dt_grid.Rows.Count > 0)
            //{
            //    idate = _dt_grid.Rows.Count;
            //    data0 = new double[idate];
            //    data1 = new double[idate];
            //    data2 = new double[idate];
            //    data3 = new double[idate];
            //    labels = new string[idate];
            //    for (int i = 0; i < idate - 1; i++)
            //    {
            //        data0[i] = Convert.ToDouble(_dt_grid.Rows[i]["F1"].ToString());
            //        data1[i] = Convert.ToDouble(_dt_grid.Rows[i]["F2"].ToString());
            //        data2[i] = Convert.ToDouble(_dt_grid.Rows[i]["F3"].ToString());
            //        data3[i] = Convert.ToDouble(_dt_grid.Rows[i]["F4"].ToString());
            //        labels[i] = _dt_grid.Rows[i]["DD"].ToString();
            //    }
            //}
            //else return;

            // The labels for the chart
            //string[] labels = { "0", "1", "2", "3", "4", "5", "6", "7", "8"

            //                  };

            // Create a XYChart object of size 600 x 300 pixels, with a pale red
            // (ffdddd) background, black border, 1 pixel 3D border effect and
            // rounded corners.

            XYChart c = new XYChart(viewer.Width, viewer.Height);

            c.setBorder(10);
            // c.setRoundedFrame();

            // Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white
            // (ffffff) background. Set horizontal and vertical grid lines to grey
            // (cccccc).
            c.setPlotArea(55, 58, c.getWidth() - 110, c.getHeight() - 150, 0xf4f4f4,
                          -1, Chart.Transparent, c.dashLineColor(0xffffff, Chart.Transparent));
            // , Chart.Transparent, -1, 0xffffff, 0xffffff
            // Add a legend box at (55, 32) (top of the chart) with horizontal
            // layout. Use 9 pts Arial Bold font. Set the background and border color
            // to Transparent.
            //c.addLegend(55, 32, false, "Arial Bold", 9).setBackground(
            //    Chart.Transparent);

            // Add a title box to the chart using 15 pts Times Bold Italic font. The
            // title is in CDML and includes embedded images for highlight. The text
            // is white (ffffff) on a dark red (880000) background, with soft
            // lighting effect from the right side.
            //c.addTitle(
            //    "<*block,valign=absmiddle*><*img=star.png*><*img=star.png*> " +
            //    "Performance Enhancer <*img=star.png*><*img=star.png*><*/*>",
            //    "Times New Roman Bold Italic", 15, 0xffffff).setBackground(0x880000,
            //    -1, Chart.softLighting(Chart.Right));

            // Add a title to the y axis
            // c.yAxis().setTitle("Energy Concentration (KJ per liter)");

            // Set the labels on the x axis
            c.xAxis().setLabels(labels);

            // Add a title to the x axis using CMDL
            //c.xAxis().setTitle(
            //    "<*block,valign=absmiddle*><*img=clock.png*>  Elapsed Time (hour)" +
            //    "<*/*>");
            c.yAxis().setLinearScale(0, _max_chart + 50);
            // Set the axes width to 2 pixels
            c.xAxis().setWidth(2);
            //c.yAxis().setWidth(2);

            c.xAxis().setTitle(" (Date)  ", "Arial Bold ", 15);


            c.addLegend(55, 5, false, "Arial Bold", 13).setBackground(
                Chart.Transparent);

            // Add a spline layer to the chart

            c.yAxis().setLabelStyle("Calibri Bold", 12);
            c.xAxis().setLabelStyle("Calibri Bold", 11);
            c.yAxis().setWidth(2);

            c.setNumberFormat(',');

            SplineLayer layer = c.addSplineLayer();

            // Set the default line width to 2 pixels
            layer.setLineWidth(5);

            // Add a data set to the spline layer, using blue (0000c0) as the line
            // color, with yellow (ffff00) circle symbols.
            layer.addDataSet(data0, 0x0000c0, "Fatory 1").setDataSymbol(
                Chart.NoShape, 20, 0xffff00);

            // Add a data set to the spline layer, using brown (982810) as the line
            // color, with pink (f040f0) diamond symbols.
            layer.addDataSet(data1, 0x982810, "Fatory 2").setDataSymbol(
                Chart.NoShape, 20, 0xf040f0);

            layer.addDataSet(data2, 0xdb6e25, "Fatory 3").setDataSymbol(
                Chart.NoShape, 20, 0x0050f0);

            layer.addDataSet(data3, 0x004000, "Fatory 4").setDataSymbol(
                Chart.NoShape, 20, 0xf04000);

            // Add a custom CDML text at the bottom right of the plot area as the
            // logo
            //c.addText(575, 250,
            //    "<*block,valign=absmiddle*><*img=small_molecule.png*> <*block*>" +
            //    "<*font=Times New Roman Bold Italic,size=10,color=804040*>" +
            //    "Molecular\nEngineering<*/*>").setAlignment(Chart.BottomRight);

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            //viewer.ImageMap = c.getHTMLImageMap("clickable", "",
            //    "title='{dataSetName} at t = {xLabel} hour: {value} KJ/liter'");
        }
        public void createChart4(WinChartViewer viewer, string img)
        {
            // The data for the chart
            Chart.setLicenseCode("DEVP-2LSU-B4LX-YCTY-2DF2-77EE");
            double[] data = data_w4;

            // The labels for the chart
            string[] labels = label_w4;

            // In the pareto chart, the line data are just the accumulation of the
            // raw data, scaled to a range of 0 - 100%
            ArrayMath lineData = new ArrayMath(data);

            lineData.acc();
            double scaleFactor = lineData.max() / 100;

            if (scaleFactor == 0)
            {
                // Avoid division by zero error for zero data
                scaleFactor = 1;
            }
            lineData.div2(scaleFactor);

            // Create a XYChart object of size 480 x 300 pixels. Set background color
            // to brushed silver, with a grey (bbbbbb) border and 2 pixel 3D raised
            // effect. Use rounded corners. Enable soft drop shadow.
            // XYChart c = new XYChart(400, 300, Chart.brushedSilverColor(), 0xbbbbbb, 2);
            XYChart c = new XYChart(viewer.Width, viewer.Height);

            c.setBorder(10);
            // c.setRoundedFrame();
            // c.setDropShadow();

            // Add a title to the chart using 15 points Arial Italic. Set top/bottom
            // margins to 12 pixels.

            ChartDirector.TextBox title = c.addTitle(Chart.Top, _txtTit4,
                                                     "Arial Bold", 12, 0xffffff, 0x1c86ee);
            title.setMargin2(10, 10, 6, 12);
            title.setPos(10, 3);
            title.setSize(viewer.Width - 20, 30);

            // Tentatively set the plotarea at (50, 40). Set the width to 100 pixels
            // less than the chart width, and the height to 80 pixels less than the
            // chart height. Use pale grey (f4f4f4) background, transparent border,
            // and dark grey (444444) dotted grid lines.
            //c.setPlotArea(50, 40, c.getWidth() - 100, c.getHeight() - 80, 0xf4f4f4,
            //    -1, Chart.Transparent, c.dashLineColor(0x444444, Chart.DotLine));
            c.setPlotArea(50, 50, c.getWidth() - 110, c.getHeight() - 250, 0xf4f4f4,
                          -1, Chart.Transparent, c.dashLineColor(0xffffff, Chart.Transparent));

            // Add a line layer for the pareto line
            LineLayer lineLayer = c.addLineLayer2();

            // Add the pareto line using deep blue (0000ff) as the color, with circle
            // symbols
            ArrayMath li = new ArrayMath(lineData.result());
            ArrayMath am = new ArrayMath(data);

            //lineLayer.addDataSet(li.mul(_cnt / 100.0).result(), 0x0000ff).setDataSymbol(
            //    Chart.CircleShape, 9, 0x0000ff, 0x0000ff);
            lineLayer.addDataSet(lineData.result(), 0x0000ff).setDataSymbol(
                Chart.CircleShape, 9, 0x0000ff, 0x0000ff);

            // Set the line width to 2 pixel
            lineLayer.setLineWidth(2);

            // Bind the line layer to the secondary (right) y-axis.
            lineLayer.setUseYAxis2();

            // Tool tip for the line layer
            lineLayer.setHTMLImageMap("", "",
                                      "title='Top {={x}+1} items: {value|2}%'");

            // Add a multi-color bar layer using the given data.
            BarLayer barLayer = c.addBarLayer(data, 0xfc8a8a);

            // BarLayer barLayer = c.addBarLayer(am.mul(_cnt / 100.0).result(), 0xfc8a8a);

            // Set soft lighting for the bars with light direction from the right
            barLayer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Right
                                                                          ));


            c.xAxis().setLabelStyle("Arial Bold", 8).setFontAngle(70);
            c.yAxis().setLabelStyle("Arial Bold", 9);
            c.yAxis2().setLabelStyle("Arial Bold", 9);

            // Tool tip for the bar layer
            // barLayer.setHTMLImageMap("", "", "title='{xLabel}: {value} pieces'");

            // Set the labels on the x axis.
            c.xAxis().setLabels(labels);

            // Set the secondary (right) y-axis scale as 0 - 100 with a tick every 20
            // units
            c.yAxis2().setLinearScale(0, 100, 10);

            // Set the format of the secondary (right) y-axis label to include a
            // percentage sign
            c.yAxis2().setLabelFormat("{value}%");

            // Set the relationship between the two y-axes, which only differ by a
            // scaling factor
            c.yAxis().setLinearScale(0, 1600, 160);
            //c.yAxis().syncAxis(c.yAxis2(), scaleFactor);

            // Set the format of the primary y-axis label foramt to show no decimal
            // point
            c.yAxis().setLabelFormat("{value|0}");
            c.setNumberFormat(',');

            // Add a title to the primary y-axis
            // c.yAxis().setTitle("Frequency");



            // Set all axes to transparent
            //  c.xAxis().setColors(Chart.Transparent);
            //  c.yAxis().setColors(Chart.Transparent);
            // c.yAxis2().setColors(Chart.Transparent);

            // Adjust the plot area size, such that the bounding box (inclusive of
            // axes) is 10 pixels from the left edge, just below the title, 10 pixels
            // from the right edge, and 20 pixels from the bottom edge.
            //c.packPlotArea(10, title.getHeight(), c.getWidth() - 10, c.getHeight() -
            //    20);

            // Output the chart
            viewer.Chart = c;

            // Include tool tip for the chart
            // viewer.ImageMap = c.getHTMLImageMap("clickable");
        }
        private void generateChart()
        {
            DataTable[] rawDataTables;

            double?yMin = null, yMax = null, y2Min = null, y2Max = null;

            imageMapAreas = new StringBuilder();

            preSetup();

            if (_rcp.Datasources.Length == 0)
            {
                drawMessage(_noDatasourcesMessage);
                finalizeChart();
                return;
            }

            if (_start == _end)
            {
                drawMessage("There is no data available for selected options.");
                finalizeChart();
                return;
            }

            //Get the data from the database
            rawDataTables = retrieveData(_rcp.Datasources, _start, _end);

            //Set the scale to be measured in days
            //Remove the auto-generated labels
            _chart.xAxis().setLinearScale(Chart.CTime(_timeZone.ToLocalTime(_start).Date),
                                          Chart.CTime(_timeZone.ToLocalTime(_end).Date.AddDays(1)), null);

            addTimestampLabels(_start, _end);

            for (int i = 0; i < rawDataTables.Length; i++)
            {
                DBTable               tableHelper;
                DateTime[]            timestamps;
                double[]              values;
                string[]              tooltips;
                DisplayDatasourceItem currDataItem;
                ConfiguredDatasource  currConfiguredDatasource;
                Color  currLineColor;
                string currDataName;

                currDataItem = _rcp.Datasources[i];

                currConfiguredDatasource = _db.ORManager.Get <ConfiguredDatasource>(currDataItem.ConfiguredDatasourceId);

                //If the datasource doesn't exist, don't process it
                if (currConfiguredDatasource == null)
                {
                    continue;
                }

                currDataName = currConfiguredDatasource.Name;

                if (rawDataTables[i].ExtendedProperties.Contains("SubTypeId"))
                {
                    DatasourceSubType currSubType;
                    int subTypeId;

                    subTypeId     = (int)rawDataTables[i].ExtendedProperties["SubTypeId"];
                    currSubType   = _db.ORManager.Get <DatasourceSubType>(subTypeId);
                    currDataName += " - " + currSubType.Name;
                }

                tableHelper = new DBTable(rawDataTables[i]);
                timestamps  = tableHelper.getColAsDateTime(0);
                values      = tableHelper.getCol(1);

                //Adjust the timestamps for the users time zone
                for (int j = 0; j < timestamps.Length; j++)
                {
                    timestamps[j] = _timeZone.ToLocalTime(timestamps[j]);
                }

                //Create an array of strings that represent the tooltips
                tooltips = new string[timestamps.Length];
                for (int j = 0; j < timestamps.Length; j++)
                {
                    tooltips[j] = getDatapointTooltip(currConfiguredDatasource, timestamps[j], values[j]);
                }

                //Determine the color to use
                if (currDataItem.Color == null)
                {
                    currLineColor = AutoLineColors[i % AutoLineColors.Length];
                }
                else
                {
                    currLineColor = (Color)currDataItem.Color;
                }

                bool useYAxis2;

                useYAxis2 = (rawDataTables.Length == 2 && i == 1);

                //Hide the axis labels when displaying 3 or more data sources
                if (rawDataTables.Length > 2)
                {
                    _chart.yAxis().setLabelFormat("");
                }

                Axis axis = null;

                //If there are more than 2 data sources, display them on different axis
                if (rawDataTables.Length > 2)
                {
                    axis = _chart.addAxis(Chart.Left, 0);
                    axis.setLabelFormat("");
                }

                //Keep a running tab of the overall min and max values
                if (rawDataTables.Length <= 2)
                {
                    if (!useYAxis2)
                    {
                        double?currYMin, currYMax;

                        ChartMath.GetDataBounds(values, out currYMin, out currYMax);
                        if (yMin == null && currYMin != null)
                        {
                            yMin = currYMin;
                        }
                        else if (currYMin != null)
                        {
                            yMin = Math.Min(currYMin.Value, yMin.Value);
                        }
                        if (yMax == null && currYMax != null)
                        {
                            yMax = currYMax;
                        }
                        else if (currYMax != null)
                        {
                            yMax = Math.Min(currYMax.Value, yMax.Value);
                        }
                    }
                    else
                    {
                        double?currYMin, currYMax;

                        ChartMath.GetDataBounds(values, out currYMin, out currYMax);
                        if (y2Min == null && currYMin != null)
                        {
                            y2Min = currYMin;
                        }
                        else if (currYMin != null)
                        {
                            y2Min = Math.Min(currYMin.Value, y2Min.Value);
                        }
                        if (y2Max == null && currYMax != null)
                        {
                            y2Max = currYMax;
                        }
                        else if (currYMax != null)
                        {
                            y2Max = Math.Min(currYMax.Value, y2Max.Value);
                        }
                    }
                }

                if (currDataItem.ShowRaw)
                {
                    LineLayer lineLayer;

                    lineLayer = _chart.addLineLayer2();
                    lineLayer.addDataSet(values, Chart.CColor(currLineColor), fixLayerNameWidth(currDataName)).setDataSymbol(
                        Chart.DiamondSymbol, 4, 0xffff80);
                    lineLayer.setXData(timestamps);
                    lineLayer.addExtraField(tooltips);                     //field0
                    lineLayer.setLineWidth(currDataItem.LineThickness);

                    if (axis == null)
                    {
                        lineLayer.setUseYAxis2(useYAxis2);
                    }
                    else
                    {
                        lineLayer.setUseYAxis(axis);
                    }
                }
                if (currDataItem.ShowTrendLine)
                {
                    TrendLayer tl;
                    tl =
                        _chart.addTrendLayer(values, _chart.dashLineColor(Chart.CColor(currLineColor), Chart.DashLine),
                                             fixLayerNameWidth(currConfiguredDatasource.Name + " Trend"));
                    tl.setLineWidth(currDataItem.LineThickness + 1);
                    tl.setXData(timestamps);
                    tl.addExtraField(new string[timestamps.Length]);                     //field0

                    if (axis == null)
                    {
                        tl.setUseYAxis2(useYAxis2);
                    }
                    else
                    {
                        tl.setUseYAxis(axis);
                    }
                }
                if (currDataItem.ShowLowess)
                {
                    SplineLayer sl;
                    sl =
                        _chart.addSplineLayer(new ArrayMath(values).lowess().result(),
                                              _chart.dashLineColor(Chart.CColor(currLineColor), Chart.DashLine),
                                              fixLayerNameWidth(currDataName));
                    sl.setLineWidth(currDataItem.LineThickness + 1);
                    sl.setXData(timestamps);
                    sl.addExtraField(new string[timestamps.Length]);                     //field0

                    if (axis == null)
                    {
                        sl.setUseYAxis2(useYAxis2);
                    }
                    else
                    {
                        sl.setUseYAxis(axis);
                    }
                }
            }

            optimizePlotArea(yMin, yMax, y2Min, y2Max);

            //Calculate the scale of the chart based on the plotted data,
            //this needs to be called before drawEvents, so the tool tip
            //locations for the events can be calculated.
            _chart.layout();

            drawEvents();
            drawLegend();
        }
Exemple #22
0
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // the names of the tasks
            string[] labels = { "Market Research",      "Define Specifications",
                                "Overall Archiecture",  "Project Planning",     "Detail Design",
                                "Software Development", "Test Plan",            "Testing and QA",
                                "User Documentation" };

            // the planned start dates and end dates for the tasks
            DateTime[] startDate = { new DateTime(2004,                                           8, 16), new DateTime(2004,                 8,
                                                                                                                       30), new DateTime(2004,   9,               13), new DateTime(2004,  9, 20),
                                     new DateTime(2004,                                           9, 27), new DateTime(2004,                10, 4), new DateTime(
                                         2004,                                                   10, 25), new DateTime(2004,                11, 1), new DateTime(2004, 11, 8) };
            DateTime[] endDate = { new DateTime(2004,                                         8, 30), new DateTime(2004,                 9, 13
                                                                                                                   ), new DateTime(2004,   9,               27), new DateTime(2004, 10, 4),
                                   new DateTime(2004,                                        10, 11), new DateTime(2004,                11, 8), new DateTime(
                                       2004,                                                 11,  8), new DateTime(2004,                11,22), new DateTime(2004, 11, 22) }

            ;

            // the actual start dates and end dates for the tasks up to now
            DateTime[] actualStartDate = { new DateTime(2004,                 8, 16), new DateTime(
                                               2004,                          8, 27), new DateTime(2004,9, 9), new DateTime(2004, 9, 18),
                                           new DateTime(2004,                 9, 22) };
            DateTime[] actualEndDate = { new DateTime(2004,                                             8, 27), new DateTime(2004,
                                                                                                                             9,                    9), new DateTime(2004,   9,27), new DateTime(2004, 10, 2),
                                         new DateTime(2004,                                            10, 8) };

            // Create a XYChart object of size 620 x 280 pixels. Set background color
            // to light green (ccffcc) with 1 pixel 3D border effect.
            XYChart c = new XYChart(620, 280, 0xccffcc, 0x000000, 1);

            // Add a title to the chart using 15 points Times Bold Itatic font, with
            // white (ffffff) text on a dark green (0x6000) background
            c.addTitle("Mutli-Layer Gantt Chart Demo", "Times New Roman Bold Italic",
                       15, 0xffffff).setBackground(0x006000);

            // Set the plotarea at (140, 55) and of size 460 x 200 pixels. Use
            // alternative white/grey background. Enable both horizontal and vertical
            // grids by setting their colors to grey (c0c0c0). Set vertical major
            // grid (represents month boundaries) 2 pixels in width
            c.setPlotArea(140, 55, 460, 200, 0xffffff, 0xeeeeee, Chart.LineColor,
                          0xc0c0c0, 0xc0c0c0).setGridWidth(2, 1, 1, 1);

            // swap the x and y axes to create a horziontal box-whisker chart
            c.swapXY();

            // Set the y-axis scale to be date scale from Aug 16, 2004 to Nov 22,
            // 2004, with ticks every 7 days (1 week)
            c.yAxis().setDateScale(new DateTime(2004, 8, 16), new DateTime(2004, 11,
                                                                           22), 86400 * 7);

            // Add a red (ff0000) dash line to represent the current day
            c.yAxis().addMark(Chart.CTime(new DateTime(2004, 10, 8)),
                              c.dashLineColor(0xff0000, Chart.DashLine));

            // Set multi-style axis label formatting. Month labels are in Arial Bold
            // font in "mmm d" format. Weekly labels just show the day of month and
            // use minor tick (by using '-' as first character of format string).
            c.yAxis().setMultiFormat(Chart.StartOfMonthFilter(),
                                     "<*font=Arial Bold*>{value|mmm d}", Chart.StartOfDayFilter(),
                                     "-{value|d}");

            // Set the y-axis to shown on the top (right + swapXY = top)
            c.setYAxisOnRight();

            // Set the labels on the x axis
            c.xAxis().setLabels(labels);

            // Reverse the x-axis scale so that it points downwards.
            c.xAxis().setReverse();

            // Set the horizontal ticks and grid lines to be between the bars
            c.xAxis().setTickOffset(0.5);

            // Use blue (0000aa) as the color for the planned schedule
            int plannedColor = 0x0000aa;

            // Use a red hash pattern as the color for the actual dates. The pattern
            // is created as a 4 x 4 bitmap defined in memory as an array of colors.
            int actualColor = c.patternColor(new int[] { 0xffffff, 0xffffff, 0xffffff,
                                                         0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000,
                                                         0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xffffff }, 4);

            // Add a box whisker layer to represent the actual dates. We add the
            // actual dates layer first, so it will be the top layer.
            BoxWhiskerLayer actualLayer = c.addBoxLayer(Chart.CTime(actualStartDate),
                                                        Chart.CTime(actualEndDate), actualColor, "Actual");

            // Set the bar height to 8 pixels so they will not block the bottom bar
            actualLayer.setDataWidth(8);

            // Add a box-whisker layer to represent the planned schedule date
            c.addBoxLayer(Chart.CTime(startDate), Chart.CTime(endDate), plannedColor,
                          "Planned").setBorderColor(Chart.SameAsMainColor);

            // Add a legend box on the top right corner (595, 60) of the plot area
            // with 8 pt Arial Bold font. Use a semi-transparent grey (80808080)
            // background.
            LegendBox b = c.addLegend(595, 60, false, "Arial Bold", 8);

            b.setAlignment(Chart.TopRight);
            b.setBackground(unchecked ((int)0x80808080), -1, 2);

            // Output the chart
            viewer.Image = c.makeImage();

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{xLabel} ({dataSetName}): {top|mmm dd, yyyy} to " +
                                                "{bottom|mmm dd, yyyy}'");
        }
        public void createChart(WinChartViewer viewer, double[] data, string img)
        {
            // The data for the chart
            Chart.setLicenseCode("DEVP-2LSU-B4LX-YCTY-2DF2-77EE");
            //double[] data = {16, 15, 9.7, 5.2, 3};

            // double[] data1 = { Chart.NoValue, -131, 35, 46 };
            // The labels for the chart
            // string[] labels = _strLabel;

            //int[] _colors = { 3394815, 0x33ccff, 0x33ccff, 0x33ccff, 28864 };

            double dMax  = NulltoZeroDouble(_dt_chart.Rows[_dt_chart.Rows.Count - 3][viewer.Name.Replace("chart_", "")]);
            double dMin  = NulltoZeroDouble(_dt_chart.Rows[_dt_chart.Rows.Count - 2][viewer.Name.Replace("chart_", "")]);
            double dIncr = NulltoZeroDouble(_dt_chart.Rows[_dt_chart.Rows.Count - 1][viewer.Name.Replace("chart_", "")]);

            // Create a XYChart object of size 480 x 300 pixels. Set background color
            // to brushed silver, with a grey (bbbbbb) border and 2 pixel 3D raised
            // effect. Use rounded corners. Enable soft drop shadow.
            // XYChart c = new XYChart(400, 300, Chart.brushedSilverColor(), 0xbbbbbb, 2);
            XYChart c = new XYChart(viewer.Width, viewer.Height);

            c.setBorder(10);

            // Add a title to the chart using 15 points Arial Italic. Set top/bottom
            // margins to 12 pixels.

            ChartDirector.TextBox title = c.addTitle(Chart.Top, _dt_chart.Rows[0][viewer.Name.Replace("chart_", "") + "_CNAME"].ToString(),
                                                     "Arial Bold", 12);
            title.setMargin2(10, 10, 6, 12);
            title.setPos(10, 3);
            title.setSize(viewer.Width - 20, 30);

            // Tentatively set the plotarea at (50, 40). Set the width to 100 pixels
            // less than the chart width, and the height to 80 pixels less than the
            // chart height. Use pale grey (f4f4f4) background, transparent border,
            // and dark grey (444444) dotted grid lines.
            c.setPlotArea(70, 50, c.getWidth() - 110, c.getHeight() - 100, 0xffffff,
                          -1, Chart.Transparent, c.dashLineColor(0xffffff, Chart.Transparent));

            // Add a line layer for the pareto line
            // ArrayMath li = new ArrayMath(data1);
            ArrayMath am = new ArrayMath(data);

            //LineLayer lineLayer = c.addLineLayer2();

            //lineLayer.addDataSet(li.mul(_cnt / 100.0).result(), 0x0000ff).setDataSymbol(
            //    Chart.CircleShape, 9, 0x0000ff, 0x0000ff);

            //// Set the line width to 2 pixel
            //lineLayer.setLineWidth(2);

            //// Bind the line layer to the secondary (right) y-axis.
            //lineLayer.setUseYAxis2();

            //lineLayer.setDataLabelFormat("{value}%");

            // Add a multi-color bar layer using the given data
            BarLayer barLayer = c.addBarLayer3(am.mul(_cnt / 100.0).result(), _colors);

            barLayer.setBorderColor(Chart.Transparent);
            barLayer.setAggregateLabelStyle();


            c.xAxis().setLabelStyle("Arial Bold", 11);
            c.yAxis().setLabelStyle("Arial   Bold", 11);
            // c.yAxis2().setLabelStyle("Arial Bold", 9);

            // Set the labels on the x axis.
            c.xAxis().setLabels(_strLabel);

            // Set the secondary (right) y-axis scale as 0 - 100 with a tick every 20
            // units
            c.yAxis().setLinearScale(dMin, dMax, dIncr);
            //  c.yAxis2().setLinearScale(-140, 60, 20);

            // Set the format of the secondary (right) y-axis label to include a
            // percentage sign
            //  c.yAxis2().setLabelFormat("{value}%");

            // Set the format of the primary y-axis label foramt to show no decimal
            // point
            c.yAxis().setLabelFormat("{value|0}");
            c.setNumberFormat(',');

            // Output the chart
            viewer.Chart = c;
        }
Exemple #24
0
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // The data for the line chart
            double[] data0 = { 42, 49, 33, 38, 51, 46, 29, 41, 44, 57, 59, 52, 37, 34,
                               51, 56, 56, 60, 70, 76, 63, 67, 75, 64, 51 };
            double[] data1 = { 50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60,
                               67, 67, 58, 59, 73, 77, 84, 82, 80, 84, 98 };
            double[] data2 = { 36, 28, 25, 33, 38, 20, 22, 30, 25, 33, 30, 24, 28, 15,
                               21, 26, 46, 42, 48, 45, 43, 52, 64, 60, 70 };

            // The labels for the line chart
            string[] labels = { "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",  "9",
                                "10", "11", "12", "13", "14", "15", "16", "17", "18", "19","20",
                                "21", "22", "23", "24" };

            // Create an XYChart object of size 600 x 300 pixels, with a light blue
            // (EEEEFF) background, black border, 1 pxiel 3D border effect and
            // rounded corners
            XYChart c = new XYChart(600, 300, 0xeeeeff, 0x000000, 1);

            c.setRoundedFrame();

            // Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white
            // background. Turn on both horizontal and vertical grid lines with light
            // grey color (0xcccccc)
            c.setPlotArea(55, 58, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);

            // Add a legend box at (50, 30) (top of the chart) with horizontal
            // layout. Use 9 pts Arial Bold font. Set the background and border color
            // to Transparent.
            c.addLegend(50, 30, false, "Arial Bold", 9).setBackground(
                Chart.Transparent);

            // Add a title box to the chart using 15 pts Times Bold Italic font, on a
            // light blue (CCCCFF) background with glass effect. white (0xffffff) on
            // a dark red (0x800000) background, with a 1 pixel 3D border.
            c.addTitle("Application Server Throughput",
                       "Times New Roman Bold Italic", 15).setBackground(0xccccff, 0x000000,
                                                                        Chart.glassEffect());

            // Add a title to the y axis
            c.yAxis().setTitle("MBytes per hour");

            // Set the labels on the x axis.
            c.xAxis().setLabels(labels);

            // Display 1 out of 3 labels on the x-axis.
            c.xAxis().setLabelStep(3);

            // Add a title to the x axis
            c.xAxis().setTitle("Jun 12, 2006");

            // Add a line layer to the chart
            LineLayer layer = c.addLineLayer2();

            // Set the default line width to 2 pixels
            layer.setLineWidth(2);

            // Add the three data sets to the line layer. For demo purpose, we use a
            // dash line color for the last line
            layer.addDataSet(data0, 0xff0000, "Server #1");
            layer.addDataSet(data1, 0x008800, "Server #2");
            layer.addDataSet(data2, c.dashLineColor(0x3333ff, Chart.DashLine),
                             "Server #3");

            // Output the chart
            viewer.Image = c.makeImage();

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='[{dataSetName}] Hour {xLabel}: {value} MBytes'");
        }
Exemple #25
0
        private void drawChart(WinChartViewer viewer)
        {
            DateTime viewPortStartDate = beginDate.AddSeconds(Math.Round(viewer.ViewPortLeft * dateRange));
            DateTime viewPortEndDate = viewPortStartDate.AddSeconds(Math.Round(viewer.ViewPortWidth * dateRange));
            TimeSpan hoursCalc = viewPortEndDate.Subtract(viewPortStartDate);
            int hours = (hoursCalc.Days * 24) + hoursCalc.Hours;
            viewPortEndDate = viewPortEndDate.AddMinutes(12 * hours); // hack to show hour labels
            Double axisLowerLimit = 0 + viewer.ViewPortTop * rowRange;
            Double axisUpperLimit = axisLowerLimit + viewer.ViewPortHeight * (rowRange);

            XYChart c = new XYChart(winChartViewer1.Width, this.winChartViewer1.Height, 0xf0f0ff, 0, 1);
            //c.setRoundedFrame(ChartDirector.Chart.CColor(BackColor));
			
			// Set the plotarea at (52, 60) and of size 520 x 192 pixels. Use white (ffffff) 
			// background. Enable both horizontal and vertical grids by setting their colors to 
			// grey (cccccc). Set clipping mode to clip the data lines to the plot area.
            int tryToBeMoreDynamic = this.Parent.Height - 200; // instead of hardcoding height
            c.setPlotArea(100, 50, 600, tryToBeMoreDynamic, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
			c.setClipping();

            c.yAxis().setWidth(2);
            c.yAxis().setDateScale(viewPortStartDate, viewPortEndDate);
            c.yAxis().setMultiFormat(ChartDirector.Chart.StartOfHourFilter(), "<*font=bold*>{value|w hh:nn}", ChartDirector.Chart.AllPassFilter(), "{value|w hh:nn}");

            c.xAxis().setWidth(2);
            c.xAxis().setLinearScale(axisLowerLimit, axisUpperLimit, 1);
            c.xAxis().setRounding(false, false);
            c.xAxis().setColors(0xcccccc, ChartDirector.Chart.Transparent);
            c.xAxis().setReverse();

            // swap the x and y axes to create a horziontal box-whisker chart
            c.swapXY();
            BoxWhiskerLayer layer = c.addBoxWhiskerLayer2(ChartDirector.Chart.CTime(timelineBlockBegins.ToArray()), ChartDirector.Chart.CTime(timelineBlockEnds.ToArray()));
            layer.setBoxColors(timelineBlockColors.ToArray());
            layer.addExtraField(timelineBlockNames.ToArray());
            layer.setXData(timelineBlockRow.ToArray());
            layer.setDataLabelFormat("{field0}");
            layer.setDataLabelStyle("Arial Bold").setAlignment(ChartDirector.Chart.Center);
            layer.setDataWidth(35);
            //layer.setDataGap(1);
            // TimelineRow parent
            Double rowParent = 0;
            Int32 colorParentIndex = 0;
            c.xAxis().addMark(0, 0x000000).setLineWidth(2);
            foreach (Double d in timelineBlockZones)
            {
                Double rowParentBegin = rowParent; // --0.5;
                Double rowParentEnd = d + 0.5; // --0.5;

                c.xAxis().addZone(rowParentBegin, rowParentEnd, timelineRowColors[colorParentIndex]);

                Mark xMark1 = c.xAxis().addMark(rowParentBegin, 0x000000, timelineRowNames[colorParentIndex]);
                xMark1.setLineWidth(2);
                xMark1.setFontStyle("Arial Bold Italic");

                // xMark1.setAlignment(ChartDirector.Chart.Center);

                //Mark xMark2 = c.xAxis().addMark(rowParentBegin, 0x000000);
                //xMark2.setLineWidth(2);

                rowParent = d;

                colorParentIndex++;
            }

            // TimelineRow child;
            double inset = 0.5;
            Int32 colorChildIndex = 0;
            foreach (String s in timelineRows)
            {
                Mark xMark = c.xAxis().addMark(colorChildIndex + inset, 0x000000, s);
                xMark.setLineWidth(0);

                colorChildIndex++;
            }

            // Milestones
            c.yAxis2().setDateScale(viewPortStartDate, viewPortEndDate);
            c.yAxis2().setColors(ChartDirector.Chart.Transparent, ChartDirector.Chart.Transparent, ChartDirector.Chart.Transparent);

            if (bShowMilestones)
            {
                Int32 timelineMilestoneCount = 0;
                int indentY = 40;
                double previousValue = 0.0;

                List<IndexedTime> indexedTimes = new List<IndexedTime>();
                for (int i = 0; i < timelineMilestoneTimes.Count; i++)
                {
                    indexedTimes.Add(new IndexedTime(timelineMilestoneTimes[i], i));
                }
                indexedTimes.Sort();

                int one = Int32.Parse("000000", System.Globalization.NumberStyles.AllowHexSpecifier);
                int two = Int32.Parse("888888", System.Globalization.NumberStyles.AllowHexSpecifier);
                int three = Int32.Parse("BB7700", System.Globalization.NumberStyles.AllowHexSpecifier);
                Int32 lineColor = one;

                foreach (IndexedTime time in indexedTimes)
                {
                    if (indentY > tryToBeMoreDynamic-10)
                    {
                        indentY = 40;
                    }

                    indentY += 20;

                    //Int32 lineColor = timelineMilestoneColors[time.Index];
                    Double value = ChartDirector.Chart.CTime(time.Time);

                    if (!value.Equals(previousValue))
                    {
                        if (lineColor == one)
                        {
                            lineColor = two;
                        }
                        else if (lineColor == two)
                        {
                            lineColor = three;
                        }
                        else if (lineColor == three)
                        {
                            lineColor = one;
                        }
                    }

                    Mark yMark = c.yAxis2().addMark(value, c.dashLineColor(lineColor, ChartDirector.Chart.DashLine), timelineMilestoneNames[time.Index]);

                    yMark.setPos(0, indentY);
                    yMark.setFontColor(lineColor);
                    yMark.setLineWidth(2);
                    yMark.setFontStyle("Arial Bold");
                    timelineMilestoneCount++;
                    previousValue = value;
                }
            }

            if (legendStrings != null)
            {
                LegendBox l = c.addLegend(5, 5);
                l.setFontSize(legendFontSize);
                l.setCols(legendStrings.Length);

                for (int i = 0; i < legendStrings.Length; i++)
                {
                    l.addKey(legendStrings[i], legendColors[i]);
                }
            }

            if (navigator != null && componentId >= 0 && legend.Items.Count == 0)
            {
                XPathNodeIterator iTLFilter = navigator.Select("//TimelineFilter");
                List<Int32> seenIDs = new List<Int32>();

                ImageList forLegend = new ImageList();
                foreach (XPathNavigator tlFilterItem in iTLFilter)
                {
                    string filterItemColor = tlFilterItem.GetAttribute(colorAttribute, tlFilterItem.NamespaceURI);

                    if (!forLegend.Images.ContainsKey(filterItemColor))
                    {
                        try
                        {
                            Bitmap bm = new Bitmap(16, 16);
                            Graphics g = Graphics.FromImage((Image)bm);
                            Brush forGraphics = new SolidBrush(HexToColor(filterItemColor));
                            
                            g.SmoothingMode = SmoothingMode.AntiAlias;
                            g.FillRectangle(forGraphics, new Rectangle(0, 0, bm.Width, bm.Height));
                            Icon icon = Icon.FromHandle(bm.GetHicon());
                            forGraphics.Dispose();
                            g.Dispose();
                            bm.Dispose();

                            forLegend.Images.Add(filterItemColor, icon);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, "Error creating icon");
                        }
                    }
                }

                legend.SmallImageList = forLegend;

                foreach (XPathNavigator tlFilterItem in iTLFilter)
                {
                    string filterItemName = tlFilterItem.GetAttribute(nameAttribute, tlFilterItem.NamespaceURI);
                    string filterItemID = tlFilterItem.GetAttribute(idAttribute, tlFilterItem.NamespaceURI);
                    string filterItemType = tlFilterItem.GetAttribute(typeAttribute, tlFilterItem.NamespaceURI);
                    string filterItemColor = tlFilterItem.GetAttribute(colorAttribute, tlFilterItem.NamespaceURI);

                    int iParse = Int32.Parse(filterItemID);
                    if (!seenIDs.Contains(iParse))
                    {
                        legend.Items.Add(filterItemName, filterItemColor);
                        seenIDs.Add(iParse);
                    }
                }
            }

            //Int32 timelineMilestoneCount = 0;
            //foreach (String milestonName in timelineMilestoneNames)
            //{
            //    Double[] xData = { 0 };
            //    Double[] yData = { ChartDirector.Chart.CTime(timelineMilestoneTimes[timelineMilestoneCount]) };
            //    Int32 color = timelineMilestoneColors[timelineMilestoneCount];
            //    ScatterLayer sLayer = c.addScatterLayer(xData, yData, "", ChartDirector.Chart.TriangleSymbol, 13, color);
            //    timelineMilestoneCount++;

            //    // Add labels to the chart as an extra field
            //    sLayer.addExtraField(timelineMilestoneNames.ToArray());

            //    // Set the data label format to display the extra field
            //    sLayer.setDataLabelFormat("{field0}");
            //}

			viewer.Chart = c;
        }
Exemple #26
0
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // Data for the chart
            double[] data0 = { 1700, 3900, 2900, 3800, 4100, 4600, 2900, 4100, 4400,
                               5700, 5900, 5200, 3700, 3400, 5100, 5600, 5600, 6000, 7000, 7600,
                               6300, 6700, 7500, 6400, 8800 };
            double[] data1 = { 500, 550, 670, 990, 820, 730, 800, 720, 730, 790, 860,
                               800, 840, 680, 740, 890, 680, 790, 730, 770, 840, 820, 800, 840, 670 }

            ;
            double[] data2 = { 46, 68, 35, 33, 38, 20, 12, 18, 15, 23, 30, 24, 28, 15,
                               21, 26, 46, 42, 38, 25, 23, 32, 24, 20, 25 };
            double[] data3 = { 0.84, 0.82, 0.82, 0.38, 0.25, 0.52, 0.54, 0.52, 0.38,
                               0.51, 0.46, 0.29,  0.5, 0.55, 0.47, 0.34, 0.52, 0.33,0.21, 0.3, 0.25,
                               0.15, 0.18, 0.22, 0.14 };

            // Labels for the chart
            string[] labels = { "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",  "9",
                                "10", "11", "12", "13", "14", "15", "16", "17", "18", "19","20",
                                "21", "22", "23", "24" };

            // Create a XYChart object of size 600 x 360 pixels. Use a vertical
            // gradient color from sky blue (aaccff) to white (ffffff) as background.
            // Set border to grey (888888). Use rounded corners. Enable soft drop
            // shadow.
            XYChart c = new XYChart(600, 360);

            c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight(), 0xaaccff,
                                                  0xffffff), 0x888888);
            c.setRoundedFrame();
            c.setDropShadow();

            // Add a title box to the chart using 15 pts Arial Bold Italic font. Set
            // top margin to 16 pixels.
            ChartDirector.TextBox title = c.addTitle("Multiple Axes Demonstration",
                                                     "Arial Bold Italic", 15);
            title.setMargin2(0, 0, 16, 0);

            // Set the plotarea at (100, 80) and of size 400 x 230 pixels, with white
            // (ffffff) background. Use grey #(aaaaa) dotted lines for both
            // horizontal and vertical grid lines.
            c.setPlotArea(100, 80, 400, 230, 0xffffff, -1, -1, c.dashLineColor(
                              0xaaaaaa, Chart.DotLine), -1);

            // Add a legend box with the bottom center anchored at (300, 80) (top
            // center of the plot area). Use horizontal layout, and 8 points Arial
            // Bold font. Set background and border to transparent.
            LegendBox legendBox = c.addLegend(300, 80, false, "Arial Bold", 8);

            legendBox.setAlignment(Chart.BottomCenter);
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);

            // Set the labels on the x axis.
            c.xAxis().setLabels(labels);

            // Display 1 out of 3 labels on the x-axis.
            c.xAxis().setLabelStep(3);

            // Add a title to the x-axis
            c.xAxis().setTitle("Hour of Day");

            // Add a title on top of the primary (left) y axis.
            c.yAxis().setTitle("Power\n(Watt)").setAlignment(Chart.TopLeft2);
            // Set the axis, label and title colors for the primary y axis to red
            // (c00000) to match the first data set
            c.yAxis().setColors(0xcc0000, 0xcc0000, 0xcc0000);

            // Add a title on top of the secondary (right) y axis.
            c.yAxis2().setTitle("Load\n(Mbps)").setAlignment(Chart.TopRight2);
            // Set the axis, label and title colors for the secondary y axis to green
            // (00800000) to match the second data set
            c.yAxis2().setColors(0x008000, 0x008000, 0x008000);

            // Add the third y-axis at 50 pixels to the left of the plot area
            Axis leftAxis = c.addAxis(Chart.Left, 50);

            // Add a title on top of the third y axis.
            leftAxis.setTitle("Temp\n(C)").setAlignment(Chart.TopLeft2);
            // Set the axis, label and title colors for the third y axis to blue
            // (0000cc) to match the third data set
            leftAxis.setColors(0x0000cc, 0x0000cc, 0x0000cc);

            // Add the fouth y-axis at 50 pixels to the right of the plot area
            Axis rightAxis = c.addAxis(Chart.Right, 50);

            // Add a title on top of the fourth y axis.
            rightAxis.setTitle("Error\n(%)").setAlignment(Chart.TopRight2);
            // Set the axis, label and title colors for the fourth y axis to purple
            // (880088) to match the fourth data set
            rightAxis.setColors(0x880088, 0x880088, 0x880088);

            // Add a line layer to for the first data set using red (c00000) color,
            // with a line width of 2 pixels
            LineLayer layer0 = c.addLineLayer(data0, 0xcc0000, "Power");

            layer0.setLineWidth(2);

            // Add a line layer to for the second data set using green (00c0000)
            // color, with a line width of 2 pixels. Bind the layer to the secondary
            // y-axis.
            LineLayer layer1 = c.addLineLayer(data1, 0x008000, "Load");

            layer1.setLineWidth(2);
            layer1.setUseYAxis2();

            // Add a line layer to for the third data set using blue (0000cc) color,
            // with a line width of 2 pixels. Bind the layer to the third y-axis.
            LineLayer layer2 = c.addLineLayer(data2, 0x0000cc, "Temperature");

            layer2.setLineWidth(2);
            layer2.setUseYAxis(leftAxis);

            // Add a line layer to for the fourth data set using purple (880088)
            // color, with a line width of 2 pixels. Bind the layer to the fourth
            // y-axis.
            LineLayer layer3 = c.addLineLayer(data3, 0x880088, "Error Rate");

            layer3.setLineWidth(2);
            layer3.setUseYAxis(rightAxis);

            // Output the chart
            viewer.Image = c.makeImage();

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} at hour {xLabel} = {value}'");
        }
Exemple #27
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the bars and the marks
            double[] barData  = { 100, 125, 245, 147, 67, 96, 160, 145, 97, 167, 220, 125 };
            double[] markData = { 85, 156, 220, 120, 80, 110, 140, 130, 111, 180, 175, 100 };

            // The labels for the bar chart
            string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept",
                                "Oct", "Nov", "Dec" };

            // Create a XYChart object of size 480 x 360 pixels. Use a vertical gradient color from
            // pale blue (e8f0f8) to sky blue (aaccff) spanning half the chart height as background.
            // Set border to blue (88aaee). Use rounded corners. Enable soft drop shadow.
            XYChart c = new XYChart(480, 360);

            c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight() / 2, 0xe8f0f8, 0xaaccff),
                            0x88aaee);
            c.setRoundedFrame();
            c.setDropShadow();

            // Add a title to the chart using 15 points Arial Italic font. Set top/bottom margins to
            // 12 pixels.
            ChartDirector.TextBox title = c.addTitle("Bars with Marks Demonstration",
                                                     "Arial Italic", 15);
            title.setMargin2(0, 0, 12, 12);

            // Tentatively set the plotarea to 50 pixels from the left edge to allow for the y-axis,
            // and to just under the title. Set the width to 65 pixels less than the chart width,
            // and the height to reserve 90 pixels at the bottom for the x-axis and the legend box.
            // Use pale blue (e8f0f8) background, transparent border, and grey (888888) dotted
            // horizontal grid lines.
            c.setPlotArea(50, title.getHeight(), c.getWidth() - 65, c.getHeight() - title.getHeight(
                              ) - 90, 0xe8f0f8, -1, Chart.Transparent, c.dashLineColor(0x888888, Chart.DotLine));

            // Add a legend box where the bottom-center is anchored to the 15 pixels above the
            // bottom-center of the chart. Use horizontal layout and 8 points Arial font.
            LegendBox legendBox = c.addLegend(c.getWidth() / 2, c.getHeight() - 15, false, "Arial",
                                              8);

            legendBox.setAlignment(Chart.BottomCenter);

            // Set the legend box background and border to pale blue (e8f0f8) and bluish grey
            // (445566)
            legendBox.setBackground(0xe8f0f8, 0x445566);

            // Use rounded corners of 5 pixel radius for the legend box
            legendBox.setRoundedCorners(5);

            // Use line style legend key
            legendBox.setLineStyleKey();

            // Set axes to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);

            // Set the labels on the x axis
            c.xAxis().setLabels(labels);

            // Add a box-whisker layer with just the middle mark visible for the marks. Use red
            // (ff0000) color for the mark, with a line width of 2 pixels and 10% horizontal gap
            BoxWhiskerLayer markLayer = c.addBoxWhiskerLayer(null, null, null, null, markData, -1,
                                                             0xff0000);

            markLayer.setLineWidth(2);
            markLayer.setDataGap(0.1);

            // Add the legend key for the mark line
            legendBox.addKey("Target", 0xff0000, 2);

            // Tool tip for the mark layer
            markLayer.setHTMLImageMap("", "", "title='Target at {xLabel}: {med}'");

            // Add a blue (0066cc) bar layer using the given data.
            BarLayer barLayer = c.addBarLayer(barData, 0x0066cc, "Actual");

            // Use soft lighting effect for the bars with light direction from left.
            barLayer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Left));

            // Tool tip for the bar layer
            barLayer.setHTMLImageMap("", "", "title='{dataSetName} at {xLabel}: {value}'");

            // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10
            // pixels from the left edge, just below the title, 15 pixels from the right edge, and
            // 10 pixels above the legend box.
            c.packPlotArea(10, title.getHeight(), c.getWidth() - 15, c.layoutLegend().getTopY() - 10
                           );

            // Output the chart
            viewer.Chart = c;

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable");
        }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // Data points which more unevenly spaced in time
            double[]   data0Y = { 62, 69, 53, 58, 84, 76, 49, 61, 64, 77, 79 };
            DateTime[] data0X = { new DateTime(2007,                                                                      1,  1), new DateTime(2007,                 1,  2), new DateTime(2007,
                                                                                                                                                                                          1,                    5), new DateTime(2007,   1,                7), new DateTime(2007,   1,10), new DateTime(2007, 1, 14),
                                  new DateTime(2007,                                                                      1, 17), new DateTime(2007,                 1, 18), new DateTime(2007, 1, 19),
                                  new DateTime(2007,                                                                      1, 20), new DateTime(2007,                 1, 21) };

            // Data points which are evenly spaced in a certain time range
            double[] data1Y     = { 36, 25, 28, 38, 20, 30, 27, 35, 65, 60, 40, 73, 62, 90, 75, 72 };
            DateTime data1Start = new DateTime(2007, 1, 1);
            DateTime data1End   = new DateTime(2007, 1, 16);

            // Data points which are evenly spaced in another time range, in which the spacing is
            // different from the above series
            double[] data2Y     = { 25, 15, 30, 23, 32, 55, 45 };
            DateTime data2Start = new DateTime(2007, 1, 9);
            DateTime data2End   = new DateTime(2007, 1, 21);

            // Create a XYChart object of size 600 x 400 pixels. Use a vertical gradient color from light
            // blue (99ccff) to white (ffffff) spanning the top 100 pixels as background. Set border to
            // grey (888888). Use rounded corners. Enable soft drop shadow.
            XYChart c = new XYChart(600, 400);

            c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888);
            c.setRoundedFrame();
            c.setDropShadow();

            // Add a title using 18pt Times New Roman Bold Italic font. Set top margin to 16 pixels.
            c.addTitle("Product Line Order Backlog", "Times New Roman Bold Italic", 18).setMargin2(0, 0,
                                                                                                   16, 0);

            // Set the plotarea at (60, 80) and of 510 x 275 pixels in size. Use transparent border and
            // dark grey (444444) dotted grid lines
            PlotArea plotArea = c.setPlotArea(60, 80, 510, 275, -1, -1, Chart.Transparent,
                                              c.dashLineColor(0x444444, 0x0101), -1);

            // Add a legend box where the top-center is anchored to the horizontal center of the plot
            // area at y = 45. Use horizontal layout and 10 points Arial Bold font, and transparent
            // background and border.
            LegendBox legendBox = c.addLegend(plotArea.getLeftX() + plotArea.getWidth() / 2, 45, false,
                                              "Arial Bold", 10);

            legendBox.setAlignment(Chart.TopCenter);
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);

            // Set x-axis tick density to 75 pixels and y-axis tick density to 30 pixels. ChartDirector
            // auto-scaling will use this as the guidelines when putting ticks on the x-axis and y-axis.
            c.yAxis().setTickDensity(30);
            c.xAxis().setTickDensity(75);

            // Set all axes to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);

            // Set the x-axis margins to 15 pixels, so that the horizontal grid lines can extend beyond
            // the leftmost and rightmost vertical grid lines
            c.xAxis().setMargin(15, 15);

            // Set axis label style to 8pt Arial Bold
            c.xAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis2().setLabelStyle("Arial Bold", 8);

            // Add axis title using 10pt Arial Bold Italic font
            c.yAxis().setTitle("Backlog in USD millions", "Arial Bold Italic", 10);

            // Add the first data series
            LineLayer layer0 = c.addLineLayer2();

            layer0.addDataSet(data0Y, 0xff0000, "Quantum Computer").setDataSymbol(
                Chart.GlassSphere2Shape, 11);
            layer0.setXData(data0X);
            layer0.setLineWidth(3);

            // Add the second data series
            LineLayer layer1 = c.addLineLayer2();

            layer1.addDataSet(data1Y, 0x00ff00, "Atom Synthesizer").setDataSymbol(
                Chart.GlassSphere2Shape, 11);
            layer1.setXData2(data1Start, data1End);
            layer1.setLineWidth(3);

            // Add the third data series
            LineLayer layer2 = c.addLineLayer2();

            layer2.addDataSet(data2Y, 0xff6600, "Proton Cannon").setDataSymbol(Chart.GlassSphere2Shape,
                                                                               11);
            layer2.setXData2(data2Start, data2End);
            layer2.setLineWidth(3);

            // Output the chart
            viewer.Image = c.makeWebImage(Chart.PNG);

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "",
                                                "title='Backlog of {dataSetName} at {x|mm/dd/yyyy}: US$ {value}M'");
        }
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // The x and y coordinates of the grid
            double[] dataX = { -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4,
                               5,    6,  7,  8,  9, 10 };
            double[] dataY = { -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4,
                               5,    6,  7,  8,  9, 10 };

            // The values at the grid points. In this example, we will compute the
            // values using the formula z = Sin(x / 2) * Sin(y / 2).
            double[] dataZ = new double[(dataX.Length) * (dataY.Length)];
            for (int yIndex = 0; yIndex < dataY.Length; ++yIndex)
            {
                double y = dataY[yIndex];
                for (int xIndex = 0; xIndex < dataX.Length; ++xIndex)
                {
                    double x = dataX[xIndex];
                    dataZ[yIndex * (dataX.Length) + xIndex] = Math.Sin(x / 2.0) *
                                                              Math.Sin(y / 2.0);
                }
            }

            // Create a XYChart object of size 600 x 500 pixels
            XYChart c = new XYChart(600, 500);

            // Add a title to the chart using 18 points Times New Roman Bold Italic
            // font
            c.addTitle("Nano Lattice Twister Field Intensity        ",
                       "Times New Roman Bold Italic", 18);

            // Set the plotarea at (75, 40) and of size 400 x 400 pixels. Use
            // semi-transparent black (80000000) dotted lines for both horizontal and
            // vertical grid lines
            c.setPlotArea(75, 40, 400, 400, -1, -1, -1, c.dashLineColor(
                              unchecked ((int)0x80000000), Chart.DotLine), -1);

            // Set x-axis and y-axis title using 12 points Arial Bold Italic font
            c.xAxis().setTitle("Lattice X Direction (nm)", "Arial Bold Italic", 12);
            c.yAxis().setTitle("Lattice Y Direction (nm)", "Arial Bold Italic", 12);

            // Set x-axis and y-axis labels to use Arial Bold font
            c.xAxis().setLabelStyle("Arial Bold");
            c.yAxis().setLabelStyle("Arial Bold");

            // When auto-scaling, use tick spacing of 40 pixels as a guideline
            c.yAxis().setTickDensity(40);
            c.xAxis().setTickDensity(40);

            // Add a contour layer using the given data
            ContourLayer layer = c.addContourLayer(dataX, dataY, dataZ);

            // Set the contour color to transparent
            layer.setContourColor(Chart.Transparent);

            // Move the grid lines in front of the contour layer
            c.getPlotArea().moveGridBefore(layer);

            // Add a color axis (the legend) in which the left center point is
            // anchored at (495, 240). Set the length to 370 pixels and the labels on
            // the right side.
            ColorAxis cAxis = layer.setColorAxis(495, 240, Chart.Left, 370,
                                                 Chart.Right);

            // Add a bounding box to the color axis using light grey (eeeeee) as the
            // background and dark grey (444444) as the border.
            cAxis.setBoundingBox(0xeeeeee, 0x444444);

            // Add a title to the color axis using 12 points Arial Bold Italic font
            cAxis.setTitle("Twist Pressure (Twist-Volt)", "Arial Bold Italic", 12);

            // Set color axis labels to use Arial Bold font
            cAxis.setLabelStyle("Arial Bold");

            // Use smooth gradient coloring
            cAxis.setColorGradient(true);

            // Output the chart
            viewer.Image = c.makeImage();
        }
Exemple #30
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // In this example, the data points are unevenly spaced on the x-axis
            double[]   dataY = { 4.7, 4.7, 6.6, 2.2, 4.7, 4.0, 4.0, 5.1, 4.5, 4.5, 6.8, 4.5, 4, 2.1, 3, 2.5,
                                 2.5, 3.1 };
            DateTime[] dataX = { new DateTime(1999,                                                                   7,  1), new DateTime(2000,                 1,  1), new DateTime(2000,                 2,
                                                                                                                                                                                      1), new DateTime(2000,   4,                1), new DateTime(2000,   5,                8), new DateTime(2000,  7, 5),
                                 new DateTime(2001,                                                                   3,  5), new DateTime(2001,                 4,  7), new DateTime(2001,                 5, 9),
                                 new DateTime(2002,                                                                   2,  4), new DateTime(2002,                 4,  4), new DateTime(2002,                 5, 8),
                                 new DateTime(2002,                                                                   7,  7), new DateTime(2002,                 8, 30), new DateTime(2003,                 1, 2),
                                 new DateTime(2003,                                                                   2, 16), new DateTime(2003,                11,  6), new DateTime(2004,                 1, 4) };

            // Data points are assigned different symbols based on point type
            double[] pointType = { 0, 1, 0, 1, 2, 1, 0, 0, 1, 1, 2, 2, 1, 0, 2, 1, 2, 0 };

            // Create a XYChart object of size 480 x 320 pixels. Use a vertical gradient color from pale
            // blue (e8f0f8) to sky blue (aaccff) spanning half the chart height as background. Set
            // border to blue (88aaee). Use rounded corners. Enable soft drop shadow.
            XYChart c = new XYChart(480, 320);

            c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight() / 2, 0xe8f0f8, 0xaaccff),
                            0x88aaee);
            c.setRoundedFrame();
            c.setDropShadow();

            // Add a title to the chart using 15 points Arial Italic font. Set top/bottom margins to 12
            // pixels.
            ChartDirector.TextBox title = c.addTitle("Multi-Symbol Line Chart Demo", "Arial Italic", 15);
            title.setMargin2(0, 0, 12, 12);

            // Tentatively set the plotarea to 50 pixels from the left edge to allow for the y-axis, and
            // to just under the title. Set the width to 65 pixels less than the chart width, and the
            // height to reserve 90 pixels at the bottom for the x-axis and the legend box. Use pale blue
            // (e8f0f8) background, transparent border, and grey (888888) dotted horizontal and vertical
            // grid lines.
            c.setPlotArea(50, title.getHeight(), c.getWidth() - 65, c.getHeight() - title.getHeight() -
                          90, 0xe8f0f8, -1, Chart.Transparent, c.dashLineColor(0x888888, Chart.DotLine), -1);

            // Add a legend box where the bottom-center is anchored to the 12 pixels above the
            // bottom-center of the chart. Use horizontal layout and 8 points Arial font.
            LegendBox legendBox = c.addLegend(c.getWidth() / 2, c.getHeight() - 12, false, "Arial Bold",
                                              8);

            legendBox.setAlignment(Chart.BottomCenter);

            // Set the legend box background and border to pale blue (e8f0f8) and bluish grey (445566)
            legendBox.setBackground(0xe8f0f8, 0x445566);

            // Use rounded corners of 5 pixel radius for the legend box
            legendBox.setRoundedCorners(5);

            // Set the y axis label format to display a percentage sign
            c.yAxis().setLabelFormat("{value}%");

            // Set y-axis title to use 10 points Arial Bold Italic font
            c.yAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 10);

            // Set axis labels to use Arial Bold font
            c.yAxis().setLabelStyle("Arial Bold");
            c.xAxis().setLabelStyle("Arial Bold");

            // We add the different data symbols using scatter layers. The scatter layers are added
            // before the line layer to make sure the data symbols stay on top of the line layer.

            // We select the points with pointType = 0 (the non-selected points will be set to NoValue),
            // and use yellow (ffff00) 15 pixels high 5 pointed star shape symbols for the points. (This
            // example uses both x and y coordinates. For charts that have no x explicitly coordinates,
            // use an empty array as dataX.)
            c.addScatterLayer(Chart.CTime(dataX), new ArrayMath(dataY).selectEQZ(pointType, Chart.NoValue
                                                                                 ).result(), "Point Type 0", Chart.StarShape(5), 15, 0xffff00);

            // Similar to above, we select the points with pointType - 1 = 0 and use green (ff00) 13
            // pixels high six-sided polygon as symbols.
            c.addScatterLayer(Chart.CTime(dataX), new ArrayMath(dataY).selectEQZ(new ArrayMath(pointType
                                                                                               ).sub(1).result(), Chart.NoValue).result(), "Point Type 1", Chart.PolygonShape(6), 13,
                              0x00ff00);

            // Similar to above, we select the points with pointType - 2 = 0 and use red (ff0000) 13
            // pixels high X shape as symbols.
            c.addScatterLayer(Chart.CTime(dataX), new ArrayMath(dataY).selectEQZ(new ArrayMath(pointType
                                                                                               ).sub(2).result(), Chart.NoValue).result(), "Point Type 2", Chart.Cross2Shape(), 13,
                              0xff0000);

            // Finally, add a blue (0000ff) line layer with line width of 2 pixels
            LineLayer layer = c.addLineLayer(dataY, 0x0000ff);

            layer.setXData(Chart.CTime(dataX));
            layer.setLineWidth(2);

            // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10 pixels
            // from the left edge, just below the title, 25 pixels from the right edge, and 8 pixels
            // above the legend box.
            c.packPlotArea(10, title.getHeight(), c.getWidth() - 25, c.layoutLegend().getTopY() - 8);

            // Output the chart
            viewer.Image = c.makeWebImage(Chart.PNG);

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "", "title='{x|mmm dd, yyyy}: {value}%'");
        }
Exemple #31
0
        private void LoadChart(DataTable dtCuocGoiTheoCa)
        {
            try
            {
                if (dtCuocGoiTheoCa.Rows.Count > 0)
                {
                    double[] arrCuocGoiTaxi         = new double[dtCuocGoiTheoCa.Rows.Count];
                    double[] arrCuocGoiDonDuocKhach = new double[dtCuocGoiTheoCa.Rows.Count];
                    double[] arrCuocGoiTruotHoan    = new double[dtCuocGoiTheoCa.Rows.Count];
                    double[] arrCuocGoiKhongxe      = new double[dtCuocGoiTheoCa.Rows.Count];
                    double[] arrCuocGoiMoiGioi      = new double[dtCuocGoiTheoCa.Rows.Count];
                    double[] arrCuocGoiVangLai      = new double[dtCuocGoiTheoCa.Rows.Count];
                    string[] lableVertical          = new string[dtCuocGoiTheoCa.Rows.Count];
                    int      MaxCuocGoi             = 0;
                    int      i = 0;
                    foreach (DataRow dr in dtCuocGoiTheoCa.Rows)
                    {
                        // Ca , Tu, Den,TongTaxi,TongGoiLai,TOngKhieuNai,TongGoiKhac,Tong,TongGoiNho,TongDonDuoc,PhanTramDonDuoc, TongTruotHoan,,
                        // TongKhongXe,PhanTramKhongXe, TongKhongXacDinh , PhanTramKhongXacDinh, TongCuocTaxiMoiGioi
                        if (dr["TongTaxi"] != null && dr["TongTaxi"].ToString().Length > 0)
                        {
                            arrCuocGoiTaxi[i] = Convert.ToInt32(dr["TongTaxi"].ToString());
                        }
                        else
                        {
                            arrCuocGoiTaxi[i] = 0;
                        }
                        if (dr["TongDonDuoc"] != null && dr["TongDonDuoc"].ToString().Length > 0)
                        {
                            arrCuocGoiDonDuocKhach[i] = (int)dr["TongDonDuoc"];
                        }
                        else
                        {
                            arrCuocGoiDonDuocKhach[i] = 0;
                        }
                        if (dr["TongTruotHoan"] != null && dr["TongTruotHoan"].ToString().Length > 0)
                        {
                            arrCuocGoiTruotHoan[i] = (int)dr["TongTruotHoan"];
                        }
                        else
                        {
                            arrCuocGoiTruotHoan[i] = 0;
                        }
                        if (dr["TongKhongXe"] != null && dr["TongKhongXe"].ToString().Length > 0)
                        {
                            arrCuocGoiKhongxe[i] = (int)dr["TongKhongXe"];
                        }
                        else
                        {
                            arrCuocGoiKhongxe[i] = 0;
                        }
                        if (dr["TongCuocTaxiMoiGioi"] != null && dr["TongCuocTaxiMoiGioi"].ToString().Length > 0)
                        {
                            arrCuocGoiMoiGioi[i] = (int)dr["TongCuocTaxiMoiGioi"];
                        }
                        else
                        {
                            arrCuocGoiMoiGioi[i] = 0;
                        }
                        arrCuocGoiVangLai[i] = arrCuocGoiTaxi[i] - arrCuocGoiMoiGioi[i];
                        lableVertical[i]     = "Ca " + dr["Ca"].ToString();
                        i++;
                    }

                    // Create an XYChart object of size 600 x 300 pixels, with a light blue
                    // (EEEEFF) background, black border, 1 pxiel 3D border effect and
                    // rounded corners 438, 306
                    XYChart c = new XYChart(438, 306, 0xeeeeff, 0x000000, 1);
                    c.setRoundedFrame();

                    // Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white
                    // background. Turn on both horizontal and vertical grid lines with light
                    // grey color (0xcccccc)
                    c.setPlotArea(50, 40, 380, 225, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
                    //  c.setAntiAlias();



                    // Add a legend box at (50, 30) (top of the chart) with horizontal
                    // layout. Use 9 pts Arial Bold font. Set the background and border color
                    // to Transparent.
                    c.addLegend(50, 30, false, "Arial Bold", 9).setBackground(Chart.Transparent);

                    // Add a title box to the chart using 15 pts Times Bold Italic font, on a
                    // light blue (CCCCFF) background with glass effect. white (0xffffff) on
                    // a dark red (0x800000) background, with a 1 pixel 3D border.
                    c.addTitle("Biểu đồ cuộc gọi taxi theo ca",
                               "Times New Roman Bold Italic", 15).setBackground(0xccccff, 0x000000,
                                                                                Chart.glassEffect());

                    // Add a title to the y axis
                    c.yAxis().setTitle("Số cuộc gọi");
                    //c.yAxis().setLabels(lableVertical);
                    // Set the labels on the x axis.
                    c.xAxis().setTitle("Ngày " + string.Format("{0:dd/MM/yyyy}", calTuNgay.Value));
                    // c.addStepLineLayer();
                    c.xAxis().setLabels(lableVertical);


                    // c.xAxis()
                    // Display 1 out of 3 labels on the x-axis.
                    // c.xAxis().setLabelStep(3);

                    // Add a title to the x axis
                    // c.xAxis().setTitle("Jun 12, 2006");

                    // Add a line layer to the chart
                    //LineLayer layer = c.addLineLayer2();
                    BarLayer layer = c.addBarLayer2(Chart.Stack, 8);
                    // Set the default line width to 2 pixels
                    //layer.setLineWidth(2);

                    // Add the three data sets to the line layer. For demo purpose, we use a
                    // dash line color for the last line
                    // layer.addDataSet(arrCuocGoiTaxi , 0xff0000, "Gọi taxi");
                    layer.addDataSet(arrCuocGoiDonDuocKhach, 0x008800, "Đón được");
                    layer.addDataSet(arrCuocGoiTruotHoan, c.dashLineColor(0x3333ff, Chart.DashLine),
                                     "Trượt hoãn");
                    layer.addDataSet(arrCuocGoiKhongxe, 0xff00ff, "Không xe");
                    //layer.addDataSet(arrCuocGoiMoiGioi, 0xaa00ff, "Môi giới");
                    // layer.addDataSet(arrCuocGoiVangLai, 0xcc00ff, "Vãng lai");

                    // Enable bar label for the whole bar
                    layer.setAggregateLabelStyle();

                    // Enable bar label for each segment of the stacked bar
                    layer.setDataLabelStyle();

                    // output the chart
                    ChartVungKieu1.Image = c.makeImage();
                    // ChartVungKieu1.Image.Save(Configuration.GetReportPath() + "\\BieuDo1.jpg");
                    //include tool tip for the chart
                    ChartVungKieu1.ImageMap = c.getHTMLImageMap("clickable", "",
                                                                "title='[{dataSetName}] {xLabel}: {value} Cuộc gọi'");
                }
            }
            catch (Exception ex)
            {
            }
        }