Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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[] 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'");
        }
Exemplo n.º 3
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'");
        }
Exemplo n.º 4
0
        //
        // Draw the chart.
        //
        private void drawChart(WPFChartViewer viewer)
        {
            // Get the start date and end date that are visible on the chart.
            DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft));
            DateTime viewPortEndDate   = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft +
                                                                               viewer.ViewPortWidth));

            // Get the array indexes that corresponds to the visible start and end dates
            int startIndex = (int)Math.Floor(Chart.bSearch(timeStamps, viewPortStartDate));
            int endIndex   = (int)Math.Ceiling(Chart.bSearch(timeStamps, viewPortEndDate));
            int noOfPoints = endIndex - startIndex + 1;

            // Extract the part of the data array that are visible.
            DateTime[] viewPortTimeStamps  = (DateTime[])Chart.arraySlice(timeStamps, startIndex, noOfPoints);
            double[]   viewPortDataSeriesA = (double[])Chart.arraySlice(dataSeriesA, startIndex, noOfPoints);
            double[]   viewPortDataSeriesB = (double[])Chart.arraySlice(dataSeriesB, startIndex, noOfPoints);
            double[]   viewPortDataSeriesC = (double[])Chart.arraySlice(dataSeriesC, startIndex, noOfPoints);

            //
            // At this stage, we have extracted the visible data. We can use those data to plot the chart.
            //

            //================================================================================
            // Configure overall chart appearance.
            //================================================================================

            // Create an XYChart object 600 x 300 pixels in size, with pale blue (0xf0f0ff) background,
            // black (000000) rounded border, 1 pixel raised effect.
            XYChart c = new XYChart(600, 300, 0xf0f0ff, 0, 1);

            c.setRoundedFrame(0xffffff);

            // Set the plotarea at (52, 60) and of size 520 x 205 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.
            c.setPlotArea(52, 60, 520, 205, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);

            // As the data can lie outside the plotarea in a zoomed chart, we need to enable clipping.
            c.setClipping();

            // Add a top title to the chart using 15 pts Times New Roman Bold Italic font, with a light blue
            // (ccccff) background, black (000000) border, and a glass like raised effect.
            c.addTitle("Simple Zooming and Scrolling", "Times New Roman Bold Italic", 15
                       ).setBackground(0xccccff, 0x0, Chart.glassEffect());

            // Add a legend box at the top of the plot area with 9pts Arial Bold font with flow layout.
            c.addLegend(50, 33, false, "Arial Bold", 9).setBackground(Chart.Transparent, Chart.Transparent);

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

            // Add a title to the y-axis
            c.yAxis().setTitle("Price (USD)", "Arial Bold", 9);

            //================================================================================
            // Add data to chart
            //================================================================================

            //
            // In this example, we represent the data by lines. You may modify the code below to use other
            // representations (areas, scatter plot, etc).
            //

            // Add a line layer for the lines, using a line width of 2 pixels
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);

            // In this demo, we do not have too many data points. In real code, the chart may contain a lot
            // of data points when fully zoomed out - much more than the number of horizontal pixels in this
            // plot area. So it is a good idea to use fast line mode.
            layer.setFastLineMode();

            // Now we add the 3 data series to a line layer, using the color red (ff0000), green (00cc00)
            // and blue (0000ff)
            layer.setXData(viewPortTimeStamps);
            layer.addDataSet(viewPortDataSeriesA, 0xff0000, "Product Alpha");
            layer.addDataSet(viewPortDataSeriesB, 0x00cc00, "Product Beta");
            layer.addDataSet(viewPortDataSeriesC, 0x0000ff, "Product Gamma");

            //================================================================================
            // Configure axis scale and labelling
            //================================================================================

            // Set the x-axis as a date/time axis with the scale according to the view port x range.
            viewer.syncDateAxisWithViewPort("x", c.xAxis());

            // In this demo, we rely on ChartDirector to auto-label the axis. We ask ChartDirector to ensure
            // the x-axis labels are at least 75 pixels apart to avoid too many labels.
            c.xAxis().setTickDensity(75);

            //================================================================================
            // Output the chart
            //================================================================================

            viewer.Chart = c;
        }
Exemplo n.º 5
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)
        {
            // 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.makeImage();

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{x|mmm dd, yyyy}: {value}%'");
        }
Exemplo n.º 6
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)
        {
            // Use random table to generate a random series. The random table is set
            // to 1 col x 51 rows, with 9 as the seed
            RanTable rantable = new RanTable(9, 1, 51);

            // Set the 1st column to start from 100, with changes between rows from
            // -5 to +5
            rantable.setCol(0, 100, -5, 5);

            // Get the 1st column of the random table as the data set
            double[] data = rantable.getCol(0);

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

            // Set the plotarea at (50, 35) and of size 500 x 240 pixels. Enable both
            // the horizontal and vertical grids by setting their colors to grey
            // (0xc0c0c0)
            c.setPlotArea(50, 35, 500, 240).setGridColor(0xc0c0c0, 0xc0c0c0);

            // Add a title to the chart using 18 point Times Bold Itatic font.
            c.addTitle("LOWESS Generic Curve Fitting Algorithm",
                       "Times New Roman Bold Italic", 18);

            // Set the y axis line width to 3 pixels
            c.yAxis().setWidth(3);

            // Add a title to the x axis using 12 pts Arial Bold Italic font
            c.xAxis().setTitle("Server Load (TPS)", "Arial Bold Italic", 12);

            // Set the x axis line width to 3 pixels
            c.xAxis().setWidth(3);

            // Set the x axis scale from 0 - 50, with major tick every 5 units and
            // minor tick every 1 unit
            c.xAxis().setLinearScale(0, 50, 5, 1);

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

            // Add a red (0x80ff0000) data set to the chart with square symbols
            layer.addDataSet(data, unchecked ((int)0x80ff0000)).setDataSymbol(
                Chart.SquareSymbol);

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

            // Use lowess for curve fitting, and plot the fitted data using a spline
            // layer with line width set to 3 pixels
            c.addSplineLayer(new ArrayMath(data).lowess().result(), 0x0000ff
                             ).setLineWidth(3);

            // Set zero affinity to 0 to make sure the line is displayed in the most
            // detail scale
            c.yAxis().setAutoScale(0, 0, 0);

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

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='({x}, {value|2})'");
        }
        //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)
        {
            // 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 15pt 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.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} at hour {xLabel} = {value}'");
        }
Exemplo n.º 8
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 with error information
            double[] data = { 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[] 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.0, 6.6, 7.1, 5.3, 5.5, 7.9, 6.1 };

            // The 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 300 pixels, with a light grey (eeeeee)
            // background, black border, 1 pixel 3D border effect and rounded corners.
            XYChart c = new XYChart(600, 300, 0xeeeeee, 0x000000, 1);

            c.setRoundedFrame();

            // Set the plotarea at (55, 55) and of size 520 x 195 pixels, with white (ffffff)
            // background. Set horizontal and vertical grid lines to grey (cccccc).
            c.setPlotArea(55, 55, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);

            // Add a title box to the chart using 15pt Times Bold Italic font. The title is in CDML
            // and includes embedded images for highlight. The text is on a light grey (dddddd)
            // background, with glass lighting effect.
            c.addTitle(
                "<*block,valign=absmiddle*><*img=star.png*><*img=star.png*> Molecular " +
                "Temperature Control <*img=star.png*><*img=star.png*><*/*>",
                "Times New Roman Bold Italic", 15).setBackground(0xdddddd, 0, Chart.glassEffect());

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

            // Add a title to the x axis using CMDL
            c.xAxis().setTitle(
                "<*block,valign=absmiddle*><*img=clock.png*>  Elapsed Time (hour)<*/*>");

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

            // Display 1 out of 3 labels on the x-axis. Show minor ticks for remaining labels.
            c.xAxis().setLabelStep(3, 1);

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

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

            // Add a blue (0xff) data set to the line layer, with yellow (0xffff80) diamond symbols
            lineLayer.addDataSet(data, 0x0000ff).setDataSymbol(Chart.DiamondSymbol, 12, 0xffff80);

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

            // Add a box whisker layer to the chart. Use the upper and lower mark of the box whisker
            // layer to act as error zones. The upper and lower marks are computed using the
            // ArrayMath object.
            BoxWhiskerLayer errLayer = c.addBoxWhiskerLayer(null, null, new ArrayMath(data).add(
                                                                errData).result(), new ArrayMath(data).sub(errData).result(), data,
                                                            Chart.Transparent, 0xbb6633);

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

            // Set the error zone to occupy half the space between the symbols
            errLayer.setDataGap(0.5);

            // Add a custom CDML text at the bottom right of the plot area as the logo
            c.addText(575, 247,
                      "<*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. We only need to show the tool tip for the box whisker
            // layer.
            viewer.ImageMap = errLayer.getHTMLImageMap("clickable", "",
                                                       "title='Temperature at hour {xLabel}: {med} +/- {={med}-{min}} C'");
        }
Exemplo n.º 9
0
        //
        // Draw the chart.
        //
        private void drawChart(WinChartViewer viewer)
        {
            // Get the start date and end date that are visible on the chart.
            DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft));
            DateTime viewPortEndDate   = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft +
                                                                               viewer.ViewPortWidth));

            // Extract the part of the data arrays that are visible.
            DateTime[] viewPortTimeStamps  = null;
            double[]   viewPortDataSeriesA = null;
            double[]   viewPortDataSeriesB = null;
            double[]   viewPortDataSeriesC = null;

            if (currentIndex > 0)
            {
                // Get the array indexes that corresponds to the visible start and end dates
                int startIndex = (int)Math.Floor(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortStartDate));
                int endIndex   = (int)Math.Ceiling(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortEndDate));
                int noOfPoints = endIndex - startIndex + 1;

                // Extract the visible data
                viewPortTimeStamps  = (DateTime[])Chart.arraySlice(timeStamps, startIndex, noOfPoints);
                viewPortDataSeriesA = (double[])Chart.arraySlice(dataSeriesA, startIndex, noOfPoints);
                viewPortDataSeriesB = (double[])Chart.arraySlice(dataSeriesB, startIndex, noOfPoints);
                viewPortDataSeriesC = (double[])Chart.arraySlice(dataSeriesC, startIndex, noOfPoints);
            }

            //
            // At this stage, we have extracted the visible data. We can use those data to plot the chart.
            //

            //================================================================================
            // Configure overall chart appearance.
            //================================================================================

            // Create an XYChart object of size 640 x 350 pixels
            XYChart c = new XYChart(640, 350);

            // Set the plotarea at (55, 50) with width 80 pixels less than chart width, and height 85 pixels
            // less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky blue (a0c0ff)
            // as background. Set border to transparent and grid lines to white (ffffff).
            c.setPlotArea(55, 50, c.getWidth() - 85, c.getHeight() - 80, c.linearGradientColor(0, 50, 0,
                                                                                               c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // As the data can lie outside the plotarea in a zoomed chart, we need enable clipping.
            c.setClipping();

            // Add a title to the chart using 18 pts Times New Roman Bold Italic font
            c.addTitle("  Realtime Chart with Zoom/Scroll and Track Line", "Arial", 18);

            // Add a legend box at (55, 25) using horizontal layout. Use 8pts Arial Bold as font. Set the
            // background and border color to Transparent and use line style legend key.
            LegendBox b = c.addLegend(55, 25, false, "Arial Bold", 10);

            b.setBackground(Chart.Transparent);
            b.setLineStyleKey();

            // Set the x and y axis stems to transparent and the label font to 10pt Arial
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);
            c.xAxis().setLabelStyle("Arial", 10);
            c.yAxis().setLabelStyle("Arial", 10);

            // Add axis title using 10pts Arial Bold Italic font
            c.yAxis().setTitle("Ionic Temperature (C)", "Arial Bold", 10);

            //================================================================================
            // Add data to chart
            //================================================================================

            //
            // In this example, we represent the data by lines. You may modify the code below to use other
            // representations (areas, scatter plot, etc).
            //

            // Add a line layer for the lines, using a line width of 2 pixels
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);
            layer.setFastLineMode();

            // Now we add the 3 data series to a line layer, using the color red (ff0000), green (00cc00)
            // and blue (0000ff)
            layer.setXData(viewPortTimeStamps);
            layer.addDataSet(viewPortDataSeriesA, 0xff0000, "Alpha");
            layer.addDataSet(viewPortDataSeriesB, 0x00cc00, "Beta");
            layer.addDataSet(viewPortDataSeriesC, 0x0000ff, "Gamma");

            //================================================================================
            // Configure axis scale and labelling
            //================================================================================

            if (currentIndex > 0)
            {
                c.xAxis().setDateScale(viewPortStartDate, viewPortEndDate);
            }

            // For the automatic axis labels, set the minimum spacing to 75/30 pixels for the x/y axis.
            c.xAxis().setTickDensity(75);
            c.yAxis().setTickDensity(30);

            //
            // In a zoomable chart, the time range can be from a few years to a few seconds. We can need
            // to define the date/time format the various cases.
            //

            // If all ticks are year aligned, we use "yyyy" as the label format.
            c.xAxis().setFormatCondition("align", 360 * 86400);
            c.xAxis().setLabelFormat("{value|yyyy}");

            // If all ticks are month aligned, we use "mmm yyyy" in bold font as the first label of a year,
            // and "mmm" for other labels.
            c.xAxis().setFormatCondition("align", 30 * 86400);
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "<*font=bold*>{value|mmm yyyy}",
                                     Chart.AllPassFilter(), "{value|mmm}");

            // If all ticks are day algined, we use "mmm dd<*br*>yyyy" in bold font as the first label of a
            // year, and "mmm dd" in bold font as the first label of a month, and "dd" for other labels.
            c.xAxis().setFormatCondition("align", 86400);
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(),
                                     "<*block,halign=left*><*font=bold*>{value|mmm dd<*br*>yyyy}", Chart.StartOfMonthFilter(),
                                     "<*font=bold*>{value|mmm dd}");
            c.xAxis().setMultiFormat2(Chart.AllPassFilter(), "{value|dd}");

            // If all ticks are hour algined, we use "hh:nn<*br*>mmm dd" in bold font as the first label of
            // the Day, and "hh:nn" for other labels.
            c.xAxis().setFormatCondition("align", 3600);
            c.xAxis().setMultiFormat(Chart.StartOfDayFilter(), "<*font=bold*>{value|hh:nn<*br*>mmm dd}",
                                     Chart.AllPassFilter(), "{value|hh:nn}");

            // If all ticks are minute algined, then we use "hh:nn" as the label format.
            c.xAxis().setFormatCondition("align", 60);
            c.xAxis().setLabelFormat("{value|hh:nn}");

            // If all other cases, we use "hh:nn:ss" as the label format.
            c.xAxis().setFormatCondition("else");
            c.xAxis().setLabelFormat("{value|hh:nn:ss}");

            // We make sure the tick increment must be at least 1 second.
            c.xAxis().setMinTickInc(1);

            //================================================================================
            // Output the chart
            //================================================================================

            // We need to update the track line too. If the mouse is moving on the chart (eg. if
            // the user drags the mouse on the chart to scroll it), the track line will be updated
            // in the MouseMovePlotArea event. Otherwise, we need to update the track line here.
            if (!winChartViewer1.IsInMouseMoveEvent)
            {
                trackLineLabel(c, (null == viewer.Chart) ? c.getPlotArea().getRightX() :
                               viewer.PlotAreaMouseX);
            }

            viewer.Chart = c;
        }
        private void drawChart(WinChartViewer viewer)
        {
            // get the start index that are visible on the chart
            double viewPortStartIndex = viewer.getValueAtViewPort("x", viewer.ViewPortLeft);
            double viewPortEndIndex   = viewer.getValueAtViewPort("x", viewer.ViewPortLeft + viewer.ViewPortWidth);

            // Get the array indexes that corresponds to the visible start and end
            int startIndex = (int)Math.Floor(Chart.bSearch(index, viewPortStartIndex));
            int endIndex   = (int)Math.Ceiling(Chart.bSearch(index, viewPortEndIndex));

            Console.WriteLine("port start: " + viewPortStartIndex + " port end: " + viewPortEndIndex + " start: " + startIndex + " end: " + endIndex + " index length: " + index.Length);

            int noOfPoints = endIndex - startIndex + 1;

            // declaration the data set
            double[] viewPortDataSeriesCpu;
            double[] viewPortDataSeriesGpu;
            double[] viewPortDataSeriesFps;
            double[] viewPortDataSeriesCmd;
            double[] viewPortDataSeriesObj;
            double[] viewPortDataSeriesTriangle;
            double[] viewPortDataSeriesDrawTime;
            double[] viewPortDataSeriesDataSize;
            double[] viewPortDataSeriesIbLock;
            double[] viewPortDataSeriesIbSize;
            double[] viewPortDataSeriesVbLock;
            double[] viewPortDataSeriesVbSize;
            double[] viewPortDataSeriesParamSize;
            double[] viewPortDataSeriesRemoteParamSize;
            double[] viewPortDataSeriesSurLock;
            double[] viewPortDataSeriesSurSize;
            double[] viewPortDataSeriesTexLock;
            double[] viewPortDataSeriesTexSize;
            double[] viewPortDataSeriesSetTexture;
            double[] viewPortDataSeriesStateBlock;
            double[] viewPortDataSeriesVShaderCmd;
            double[] viewPortDataSeriesVShaderConst;
            double[] viewPortDataSeriesPShaderCmd;
            double[] viewPortDataSeriesPShaderConst;

            double[] viewPortIndex = (double[])Chart.arraySlice(index, startIndex, noOfPoints);
            if (this.showCpu)
            {
                viewPortDataSeriesCpu = (double[])Chart.arraySlice(cpu, startIndex, noOfPoints);
            }
            if (this.showGpu)
            {
                viewPortDataSeriesGpu = (double[])Chart.arraySlice(gpu, startIndex, noOfPoints);
            }
            if (this.showFps)
            {
                viewPortDataSeriesFps = (double[])Chart.arraySlice(fps, startIndex, noOfPoints);
            }
            if (this.showCmd)
            {
                viewPortDataSeriesCmd = (double[])Chart.arraySlice(cmd, startIndex, noOfPoints);
            }

            if (this.showObj)
            {
                viewPortDataSeriesObj = (double[])Chart.arraySlice(obj, startIndex, noOfPoints);
            }
            if (this.showTriangle)
            {
                viewPortDataSeriesTriangle = (double[])Chart.arraySlice(triangle, startIndex, noOfPoints);
            }
            if (this.showDrawTime)
            {
                viewPortDataSeriesDrawTime = (double[])Chart.arraySlice(draw, startIndex, noOfPoints);
            }
            if (this.showDataSize)
            {
                viewPortDataSeriesDataSize = (double[])Chart.arraySlice(data, startIndex, noOfPoints);
            }
            if (this.showIbLock)
            {
                viewPortDataSeriesIbLock = (double[])Chart.arraySlice(ibLock, startIndex, noOfPoints);
            }
            if (this.showIbSize)
            {
                viewPortDataSeriesIbSize = (double[])Chart.arraySlice(ibSize, startIndex, noOfPoints);
            }

            if (this.showVbLock)
            {
                viewPortDataSeriesVbLock = (double[])Chart.arraySlice(vbLock, startIndex, noOfPoints);
            }
            if (this.showVbSize)
            {
                viewPortDataSeriesVbSize = (double[])Chart.arraySlice(vbSize, startIndex, noOfPoints);
            }
            if (this.showParamSize)
            {
                viewPortDataSeriesParamSize = (double[])Chart.arraySlice(parameterSize, startIndex, noOfPoints);
            }
            if (this.showRemoteParamSize)
            {
                viewPortDataSeriesRemoteParamSize = (double[])Chart.arraySlice(remoteParamSize, startIndex, noOfPoints);
            }
            if (this.showSurLock)
            {
                viewPortDataSeriesSurLock = (double[])Chart.arraySlice(surLock, startIndex, noOfPoints);
            }

            if (this.showSurSize)
            {
                viewPortDataSeriesSurSize = (double[])Chart.arraySlice(surSize, startIndex, noOfPoints);
            }
            if (this.showTexLock)
            {
                viewPortDataSeriesTexLock = (double[])Chart.arraySlice(texLock, startIndex, noOfPoints);
            }
            if (this.showTexSize)
            {
                viewPortDataSeriesTexSize = (double[])Chart.arraySlice(texSize, startIndex, noOfPoints);
            }
            if (this.showSetTexTime)
            {
                viewPortDataSeriesSetTexture = (double[])Chart.arraySlice(setTex, startIndex, noOfPoints);
            }
            if (this.showStateBlock)
            {
                viewPortDataSeriesStateBlock = (double[])Chart.arraySlice(stateBlock, startIndex, noOfPoints);
            }

            if (this.showVShaderCmd)
            {
                viewPortDataSeriesVShaderCmd = (double[])Chart.arraySlice(vShaderCmd, startIndex, noOfPoints);
            }
            if (this.showVShaderConst)
            {
                viewPortDataSeriesVShaderConst = (double[])Chart.arraySlice(vShaderConst, startIndex, noOfPoints);
            }
            if (this.showPShaderCmd)
            {
                viewPortDataSeriesPShaderCmd = (double[])Chart.arraySlice(pShaderCmd, startIndex, noOfPoints);
            }
            if (this.showPShaderConst)
            {
                viewPortDataSeriesPShaderConst = (double[])Chart.arraySlice(pShaderConst, startIndex, noOfPoints);
            }



            // configure overall chart apperance
            XYChart c = new XYChart(820, 490);

            c.setPlotArea(55, 50, c.getWidth() - 80, c.getHeight() - 85, c.linearGradientColor(0, 50, 0, c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xfffff);

            c.setClipping();

            c.addTitle(" All charactor for game", "Times New Roman Bold Italic", 10);

            // Set legend icon style to use line style icon, sized for 8pt font
            c.getLegend().setLineStyleKey();
            c.getLegend().setFontSize(8);


            //LegendBox b = c.addLegend(55, 25, false, "Arial Bold", 8);
            //b.setBackground(Chart.Transparent);
            //b.setLineStyleKey();

            // set the axis stem to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);

            // add the y axixs title
            c.yAxis().setTitle("chractor", "Arial Bold Italic", 10);

            // add data to chart

            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);
            layer.setFastLineMode();


            layer.setXData(this.index);

            /*
             * layer.addDataSet(viewPortDataSeriesCpu, 0xff3333, "CPU");
             * layer.addDataSet(viewPortDataSeriesGpu, 0x008800, "GPU");
             * layer.addDataSet(viewPortDataSeriesFps, 0x3333cc, "FPS");
             */
            if (this.showCpu)
            {
                layer.addDataSet(cpu, 0xff3333, "CPU");
            }
            if (this.showGpu)
            {
                layer.addDataSet(gpu, 0x008800, "GPU");
            }
            if (this.showFps)
            {
                layer.addDataSet(fps, 0x3333cc, "FPS");
            }


            if (this.showCmd)
            {
                layer.addDataSet(cmd, 0x3388cc, "CMD");
            }

            if (this.showObj)
            {
                layer.addDataSet(obj, 0x8833cc, "OBJ");
            }
            if (this.showTriangle)
            {
                layer.addDataSet(triangle, 0x333388, "TRI");
            }
            if (this.showDrawTime)
            {
                layer.addDataSet(draw, 0xff0000, "DRAW");
            }
            if (this.showDataSize)
            {
                layer.addDataSet(data, 0xff00cc, "DATA");
            }
            if (this.showIbLock)
            {
                layer.addDataSet(ibLock, 0x8888cc, "IBLOCK");
            }
            if (this.showIbSize)
            {
                layer.addDataSet(ibSize, 0x8833cc, "IBSIZE");
            }

            if (this.showVbLock)
            {
                layer.addDataSet(vbLock, 0x3333cc, "VBLOCK");
            }
            if (this.showVbSize)
            {
                layer.addDataSet(vbSize, 0x3333cc, "VBSIZE");
            }
            if (this.showParamSize)
            {
                layer.addDataSet(parameterSize, 0x3333cc, "PARAM");
            }
            if (this.showRemoteParamSize)
            {
                layer.addDataSet(remoteParamSize, 0x3333cc, "REMOTE");
            }
            if (this.showSurLock)
            {
                layer.addDataSet(surLock, 0x3333cc, "SURLOCK");
            }

            if (this.showSurSize)
            {
                layer.addDataSet(surSize, 0x3333cc, "SURSIZE");
            }
            if (this.showTexLock)
            {
                layer.addDataSet(texLock, 0x3333cc, "TEXLOCK");
            }
            if (this.showTexSize)
            {
                layer.addDataSet(texSize, 0x3333cc, "TEXSIZE");
            }
            if (this.showSetTexTime)
            {
                layer.addDataSet(setTex, 0x3333cc, "SETTEX");
            }
            if (this.showStateBlock)
            {
                layer.addDataSet(stateBlock, 0x3333cc, "STATEBLOCK");
            }

            if (this.showVShaderCmd)
            {
                layer.addDataSet(vShaderCmd, 0x3333cc, "VSC");
            }
            if (this.showVShaderConst)
            {
                layer.addDataSet(vShaderConst, 0x3333cc, "VSCONST");
            }
            if (this.showPShaderCmd)
            {
                layer.addDataSet(pShaderCmd, 0x3333cc, "PSC");
            }
            if (this.showPShaderConst)
            {
                layer.addDataSet(pShaderConst, 0x3333cc, "PSCONST");
            }


            // configure the axis scale and labeling
            //viewer.syncDateAxisWithViewPort("x", c.xAxis());
            viewer.syncLinearAxisWithViewPort("x", c.xAxis());
            // If all ticks are yearly aligned, then we use "yyyy" as the label format.
            //c.xAxis().setFormatCondition("align", 32);
            //c.xAxis().setLabelFormat("{value|p4}");

            viewer.Chart = c;
        }
Exemplo n.º 11
0
        protected void Generate_Forecast(int productid)
        {
            Product info = ControllerManager.Product.GetById(productid);
            IList <TransactionHistoryWeekly> history = ControllerManager.TransactionHistoryWeekly.GetInfo(info.Id, Config.CurrentWeek, Config.CurrentDate.Year, 1);

            this.Label12.Text = info.ProductCode.ToString();
            this.Label3.Text  = info.Description.ToString();
            this.Label5.Text  = info.Provider.Name;
            this.Label7.Text  = (history[0].Stock + history[0].Purchase - history[0].Sale).ToString();
            this.Label9.Text  = info.RepositionLevel.ToString();
            this.Label11.Text = info.RepositionPoint.ToString();
            this.Label16.Text = info.LeadTime.ToString();
            this.Label1.Text  = info.Safety.ToString();

            IList <Forecast> forecast = ControllerManager.Forecast.GetForecast(info, Config.CurrentWeek, Config.CurrentDate.Year);

            this.GridView1.DataSource = forecast;
            this.GridView1.DataBind();

            //------GRAFICO-------------------------------------------
            if (forecast.Count > 0)
            {
                string[] Titulos = new string[forecast.Count];
                double[] Stock   = new double[forecast.Count];
                double[] Ventas  = new double[forecast.Count];
                double[] Compras = new double[forecast.Count];
                for (int cont = 0; cont < forecast.Count; cont++)
                {
                    Stock.SetValue(forecast[cont].FinalStock, cont);
                    Ventas.SetValue(forecast[cont].Sale, cont);
                    Compras.SetValue(forecast[cont].Purchase, cont);
                    Titulos.SetValue(forecast[cont].Week.ToString(), cont);
                }

                XYChart c = new XYChart(480, 300, 0xeeeeff, 0x000000, 3);
                c.setPlotArea(50, 70, 410, 180, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
                c.addLegend(50, 50, false, "Arial Bold", 8).setBackground(Chart.Transparent);
                c.addTitle("Graficos Estadisticos", "Verdana Bold", 12).setBackground(0xccccff, 0x000000, Chart.glassEffect());
                c.xAxis().setTitle("Semanas");
                c.yAxis().setTitle("Cantidad");

                Mark actual = c.xAxis().addMark(10, 0x000000, "SEMANA ACTUAL");
                actual.setLineWidth(1);
                actual.setAlignment(Chart.TopRight);
                actual.setFontAngle(90);
                Mark actual0 = c.xAxis().addMark(10 + info.LeadTime, 0x000000, "LEADTIME");
                actual0.setLineWidth(1);
                actual0.setAlignment(Chart.TopLeft);
                actual0.setFontAngle(90);
                LineLayer linea = c.addLineLayer();
                linea.setLineWidth(3);
                linea.addDataSet(Stock, 0x000000, "Stock Final");
                linea.addDataSet(Ventas, 0x00ff00, "Ventas");
                linea.addDataSet(Compras, 0x0000FF, "Compras");
                c.addAreaLayer(Stock, c.yZoneColor(forecast[10].Safety, unchecked ((int)0x50ff3c3c), unchecked ((int)0x500080c0)));
                c.xAxis().addZone(10, 10 + info.LeadTime, 0xdcdcdc);
                c.xAxis().setLabels(Titulos);
                c.xAxis().setLabelStep(2);
                WebChartViewer1.Image    = c.makeWebImage(Chart.PNG);
                WebChartViewer1.ImageMap = c.getHTMLImageMap("", "", "title='Semana {xLabel}: {value}'");
                WebChartViewer1.Visible  = true;
            }
        }
Exemplo n.º 12
0
        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");
        }
Exemplo n.º 13
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 chart
            double[] data0 = { 600, 800, 1200, 1500, 1800, 1900, 2000, 1950 };
            double[] data1 = { 300, 450, 500, 1000, 1500, 1600, 1650, 1600 };

            // The labels for the chart
            string[] labels = { "1995", "1996", "1997", "1998", "1999", "2000",
                                "2001", "2002" };

            // Create a XYChart object of size 450 x 250 pixels, with a pale yellow
            // (0xffffc0) background, a black border, and 1 pixel 3D border effect.
            XYChart c = new XYChart(450, 250, 0xffffc0, 0, 1);

            // Set the plotarea at (60, 45) and of size 360 x 170 pixels, using white
            // (0xffffff) as the plot area background color. Turn on both horizontal
            // and vertical grid lines with light grey color (0xc0c0c0)
            c.setPlotArea(60, 45, 360, 170, 0xffffff, -1, -1, 0xc0c0c0, -1);

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

            // Add a title to the chart using 12 pts Arial Bold/white font. Use a 1 x
            // 2 bitmap pattern as the background.
            c.addTitle("Information Resource Usage", "Arial Bold", 12, 0xffffff
                       ).setBackground(c.patternColor(new int[] { 0x000040, 0x000080 }, 2));

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

            // Reserve 8 pixels margins at both side of the x axis to avoid the first
            // and last symbols drawing outside of the plot area
            c.xAxis().setMargin(8, 8);

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

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

            // Add the first line using small_user.png as the symbol.
            layer.addDataSet(data0, 0xcf4040, "Users").setDataSymbol2(
                "small_user.png");

            // Add the first line using small_computer.png as the symbol.
            layer.addDataSet(data1, 0x40cf40, "Computers").setDataSymbol2(
                "small_computer.png");

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

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

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Number of {dataSetName} at {xLabel}: {value}'");
        }
Exemplo n.º 14
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 375 pixels
            XYChart c = new XYChart(600, 375);

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

            // Set the plotarea at (50, 55) and of 500 x 280 pixels in size. Use a
            // vertical gradient color from light blue (f9f9ff) to sky blue (aaccff)
            // as background. Set border to transparent and grid lines to white
            // (ffffff).
            c.setPlotArea(50, 55, 500, 280, c.linearGradientColor(0, 55, 0, 335,
                                                                  0xf9fcff, 0xaaccff), -1, Chart.Transparent, 0xffffff);

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

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

            // 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 axis label style to 8pts Arial Bold
            c.xAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis().setLabelStyle("Arial Bold", 8);

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

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

            // 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);

            // 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'");
        }
Exemplo n.º 15
0
        //
        // Draw the chart.
        //
        private void drawChart(WinChartViewer viewer)
        {
            // Get the start date and end date that are visible on the chart.
            DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft));
            DateTime viewPortEndDate   = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft +
                                                                               viewer.ViewPortWidth));

            // Get the array indexes that corresponds to the visible start and end dates
            int startIndex = (int)Math.Floor(Chart.bSearch(timeStamps, viewPortStartDate));
            int endIndex   = (int)Math.Ceiling(Chart.bSearch(timeStamps, viewPortEndDate));
            int noOfPoints = endIndex - startIndex + 1;

            // Extract the part of the data array that are visible.
            DateTime[] viewPortTimeStamps  = (DateTime[])Chart.arraySlice(timeStamps, startIndex, noOfPoints);
            double[]   viewPortDataSeriesA = (double[])Chart.arraySlice(dataSeriesA, startIndex, noOfPoints);
            double[]   viewPortDataSeriesB = (double[])Chart.arraySlice(dataSeriesB, startIndex, noOfPoints);
            double[]   viewPortDataSeriesC = (double[])Chart.arraySlice(dataSeriesC, startIndex, noOfPoints);

            //
            // At this stage, we have extracted the visible data. We can use those data to plot the chart.
            //

            //================================================================================
            // Configure overall chart appearance.
            //================================================================================

            // Create an XYChart object of size 640 x 350 pixels
            XYChart c = new XYChart(640, 350);

            // Set the plotarea at (55, 55) with width 80 pixels less than chart width, and height 90 pixels
            // less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky blue (a0c0ff)
            // as background. Set border to transparent and grid lines to white (ffffff).
            c.setPlotArea(55, 55, c.getWidth() - 80, c.getHeight() - 90, c.linearGradientColor(0, 55, 0,
                                                                                               c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // As the data can lie outside the plotarea in a zoomed chart, we need enable clipping.
            c.setClipping();

            // Add a title to the chart using 18 pts Times New Roman Bold Italic font
            c.addTitle("   Zooming and Scrolling with Track Line (1)", "Times New Roman Bold Italic", 18);

            // Set legend icon style to use line style icon, sized for 8pt font
            c.getLegend().setLineStyleKey();
            c.getLegend().setFontSize(8);

            // Set the axis stem to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);

            // Add axis title using 10pts Arial Bold Italic font
            c.yAxis().setTitle("Ionic Temperature (C)", "Arial Bold Italic", 10);

            //================================================================================
            // Add data to chart
            //================================================================================

            //
            // In this example, we represent the data by lines. You may modify the code below to use other
            // representations (areas, scatter plot, etc).
            //

            // Add a line layer for the lines, using a line width of 2 pixels
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);

            // In this demo, we do not have too many data points. In real code, the chart may contain a lot
            // of data points when fully zoomed out - much more than the number of horizontal pixels in this
            // plot area. So it is a good idea to use fast line mode.
            layer.setFastLineMode();

            // Now we add the 3 data series to a line layer, using the color red (ff33333), green (008800)
            // and blue (3333cc)
            layer.setXData(viewPortTimeStamps);
            layer.addDataSet(viewPortDataSeriesA, 0xff3333, "Alpha");
            layer.addDataSet(viewPortDataSeriesB, 0x008800, "Beta");
            layer.addDataSet(viewPortDataSeriesC, 0x3333cc, "Gamma");

            //================================================================================
            // Configure axis scale and labelling
            //================================================================================

            // Set the x-axis as a date/time axis with the scale according to the view port x range.
            viewer.syncDateAxisWithViewPort("x", c.xAxis());

            //
            // In this demo, the time range can be from a few years to a few days. We demonstrate how to set
            // up different date/time format based on the time range.
            //

            // If all ticks are yearly aligned, then we use "yyyy" as the label format.
            c.xAxis().setFormatCondition("align", 360 * 86400);
            c.xAxis().setLabelFormat("{value|yyyy}");

            // If all ticks are monthly aligned, then we use "mmm yyyy" in bold font as the first label of a
            // year, and "mmm" for other labels.
            c.xAxis().setFormatCondition("align", 30 * 86400);
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "<*font=bold*>{value|mmm yyyy}",
                                     Chart.AllPassFilter(), "{value|mmm}");

            // If all ticks are daily algined, then we use "mmm dd<*br*>yyyy" in bold font as the first
            // label of a year, and "mmm dd" in bold font as the first label of a month, and "dd" for other
            // labels.
            c.xAxis().setFormatCondition("align", 86400);
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(),
                                     "<*block,halign=left*><*font=bold*>{value|mmm dd<*br*>yyyy}", Chart.StartOfMonthFilter(),
                                     "<*font=bold*>{value|mmm dd}");
            c.xAxis().setMultiFormat2(Chart.AllPassFilter(), "{value|dd}");

            // For all other cases (sub-daily ticks), use "hh:nn<*br*>mmm dd" for the first label of a day,
            // and "hh:nn" for other labels.
            c.xAxis().setFormatCondition("else");
            c.xAxis().setMultiFormat(Chart.StartOfDayFilter(), "<*font=bold*>{value|hh:nn<*br*>mmm dd}",
                                     Chart.AllPassFilter(), "{value|hh:nn}");

            //================================================================================
            // Output the chart
            //================================================================================

            // We need to update the track line too. If the mouse is moving on the chart (eg. if
            // the user drags the mouse on the chart to scroll it), the track line will be updated
            // in the MouseMovePlotArea event. Otherwise, we need to update the track line here.
            if (!viewer.IsInMouseMoveEvent)
            {
                trackLineLegend(c, (null == viewer.Chart) ? c.getPlotArea().getRightX() :
                                viewer.PlotAreaMouseX);
            }

            viewer.Chart = c;
        }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // The (x, y) data for the first line
            double[] dataX0 = { 20, 90, 40, 30, 12 };
            double[] dataY0 = { 10, 40, 75, 54, 20 };

            // The (x, y) data for the second line
            double[] dataX1 = { 10, 40, 75, 54, 60 };
            double[] dataY1 = { 50, 90, 40, 30, 10 };

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

            // Set the plotarea at (55, 65) and of size 350 x 300 pixels, with white background and a
            // light grey border (0xc0c0c0). Turn on both horizontal and vertical grid lines with light
            // grey color (0xc0c0c0)
            c.setPlotArea(55, 65, 350, 300, 0xffffff, -1, 0xc0c0c0, 0xc0c0c0, -1);

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

            // Add a title to the chart using 18pt Times Bold Itatic font
            c.addTitle("Reaction Path", "Times New Roman Bold Italic", 18);

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

            // Set the y axis line width to 3 pixels
            c.yAxis().setWidth(3);

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

            // Set the x axis line width to 3 pixels
            c.xAxis().setWidth(3);

            // Add a red (0xff3333) line layer using dataX0 and dataY0
            LineLayer layer1 = c.addLineLayer(dataY0, 0xff3333, "Compound AAA");

            layer1.setXData(dataX0);

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

            // Use 9 pixel square symbols for the data points
            layer1.getDataSet(0).setDataSymbol(Chart.SquareSymbol, 9);

            // Add custom text labels to the first and last point on the scatter plot using Arial Bold
            // font
            layer1.addCustomDataLabel(0, 0, "Start", "Arial Bold");
            layer1.addCustomDataLabel(0, 4, "End", "Arial Bold");

            // Add a green (0x33ff33) line layer using dataX1 and dataY1
            LineLayer layer2 = c.addLineLayer(dataY1, 0x33ff33, "Compound BBB");

            layer2.setXData(dataX1);

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

            // Use 11 pixel diamond symbols for the data points
            layer2.getDataSet(0).setDataSymbol(Chart.DiamondSymbol, 11);

            // Add custom text labels to the first and last point on the scatter plot using Arial Bold
            // font
            layer2.addCustomDataLabel(0, 0, "Start", "Arial Bold");
            layer2.addCustomDataLabel(0, 4, "End", "Arial Bold");

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

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "",
                                                "title='[{dataSetName}] Pressure = {x} Pa, Temperature = {value} C'");
        }
Exemplo n.º 17
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // In this example, we simply use random data for the 3 data series.
            RanSeries r = new RanSeries(129);

            double[]   data0      = r.getSeries(100, 100, -15, 15);
            double[]   data1      = r.getSeries(100, 160, -15, 15);
            double[]   data2      = r.getSeries(100, 220, -15, 15);
            DateTime[] timeStamps = r.getDateSeries(100, new DateTime(2014, 1, 1), 86400);

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

            // Set default text color to dark grey (0x333333)
            c.setColor(Chart.TextColor, 0x333333);

            // Add a title box using grey (0x555555) 20pt Arial font
            c.addTitle("    Multi-Line Chart Demonstration", "Arial", 20, 0x555555);

            // Set the plotarea at (70, 70) and of size 500 x 300 pixels, with transparent background and
            // border and light grey (0xcccccc) horizontal grid lines
            c.setPlotArea(70, 70, 500, 300, Chart.Transparent, -1, Chart.Transparent, 0xcccccc);

            // Add a legend box with horizontal layout above the plot area at (70, 35). Use 12pt Arial
            // font, transparent background and border, and line style legend icon.
            LegendBox b = c.addLegend(70, 35, false, "Arial", 12);

            b.setBackground(Chart.Transparent, Chart.Transparent);
            b.setLineStyleKey();

            // Set axis label font to 12pt Arial
            c.xAxis().setLabelStyle("Arial", 12);
            c.yAxis().setLabelStyle("Arial", 12);

            // Set the x and y axis stems to transparent, and the x-axis tick color to grey (0xaaaaaa)
            c.xAxis().setColors(Chart.Transparent, Chart.TextColor, Chart.TextColor, 0xaaaaaa);
            c.yAxis().setColors(Chart.Transparent);

            // Set the major/minor tick lengths for the x-axis to 10 and 0.
            c.xAxis().setTickLength(10, 0);

            // For the automatic axis labels, set the minimum spacing to 80/40 pixels for the x/y axis.
            c.xAxis().setTickDensity(80);
            c.yAxis().setTickDensity(40);

            // Add a title to the y axis using dark grey (0x555555) 14pt Arial font
            c.yAxis().setTitle("Y-Axis Title Placeholder", "Arial", 14, 0x555555);

            // Add a line layer to the chart with 3-pixel line width
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(3);

            // Add 3 data series to the line layer
            layer.addDataSet(data0, 0x5588cc, "Alpha");
            layer.addDataSet(data1, 0xee9944, "Beta");
            layer.addDataSet(data2, 0x99bb55, "Gamma");

            // The x-coordinates for the line layer
            layer.setXData(timeStamps);

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

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "", "title='[{x|mm/dd/yyyy}] {dataSetName}: {value}'"
                                                );
        }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // The data for the upper and lower bounding lines
            double[] upperY = { 60, 60, 100, 100, 60, 60 };
            double[] lowerY = { 40, 40, 80, 80, 40, 40 };
            double[] zoneX  = { 0, 2.5, 3.5, 5.5, 6.5, 10 };

            // The data for the spline curve
            double[] curveY = { 50, 44, 54, 48, 58, 50, 90, 85, 104, 82, 96, 90, 74, 52, 35, 58, 46, 54,
                                48, 52, 50 };
            double[] curveX = { 0,   0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9,
                                9.5, 10 };

            // Create a XYChart object of size 600 x 300 pixels, with a light grey (cccccc) background,
            // black border, and 1 pixel 3D border effect.
            XYChart c = new XYChart(600, 300, 0xcccccc, 0x000000, 1);

            //Set default directory for loading images
            c.setSearchPath(Url.Content("~/Content"));

            // 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 (cccccc)
            c.setPlotArea(55, 58, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);

            // Add a legend box at (55, 32) (top of the chart) with horizontal layout. Use 9pt 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 15pt Times Bold Italic font. The title is in CDML and
            // includes embedded images for highlight. The text is white (ffffff) on a black background,
            // with a 1 pixel 3D border.
            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(0x000000, -1, 1);

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

            // Add a title to the x axis using CMDL
            c.xAxis().setTitle("<*block,valign=absmiddle*><*img=clock.png*>  Elapsed Time (hour)<*/*>");

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

            // Add a purple (800080) spline layer to the chart with a line width of 2 pixels
            SplineLayer splineLayer = c.addSplineLayer(curveY, 0x800080, "Molecular Temperature");

            splineLayer.setXData(curveX);
            splineLayer.setLineWidth(2);

            // Add a line layer to the chart with two dark green (338033) data sets, and a line width of
            // 2 pixels
            LineLayer lineLayer = c.addLineLayer2();

            lineLayer.addDataSet(upperY, 0x338033, "Target Zone");
            lineLayer.addDataSet(lowerY, 0x338033);
            lineLayer.setXData(zoneX);
            lineLayer.setLineWidth(2);

            // Color the zone between the upper zone line and lower zone line as semi-transparent light
            // green (8099ff99)
            c.addInterLineLayer(lineLayer.getLine(0), lineLayer.getLine(1), unchecked ((int)0x8099ff99),
                                unchecked ((int)0x8099ff99));

            // If the spline line gets above the upper zone line, color to area between the lines red
            // (ff0000)
            c.addInterLineLayer(splineLayer.getLine(0), lineLayer.getLine(0), 0xff0000, Chart.Transparent
                                );

            // If the spline line gets below the lower zone line, color to area between the lines blue
            // (0000ff)
            c.addInterLineLayer(splineLayer.getLine(0), lineLayer.getLine(1), Chart.Transparent, 0x0000ff
                                );

            // 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.Image = c.makeWebImage(Chart.PNG);

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "", "title='Temperature at hour {x}: {value} C'");
        }
Exemplo n.º 19
0
        //
        // Draw the chart.
        //
        private void drawChart(WPFChartViewer viewer)
        {
            // Get the start date and end date that are visible on the chart.
            double viewPortStartDate = viewer.getValueAtViewPort("x", viewer.ViewPortLeft);
            double viewPortEndDate   = viewer.getValueAtViewPort("x", viewer.ViewPortLeft + viewer.ViewPortWidth);

            // Extract the part of the data arrays that are visible.
            double[] viewPortTimeStamps  = null;
            double[] viewPortDataSeriesA = null;
            double[] viewPortDataSeriesB = null;

            if (currentIndex > 0)
            {
                // Get the array indexes that corresponds to the visible start and end dates
                int startIndex = (int)Math.Floor(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortStartDate));
                int endIndex   = (int)Math.Ceiling(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortEndDate));
                int noOfPoints = endIndex - startIndex + 1;

                // Extract the visible data
                viewPortTimeStamps  = (double[])Chart.arraySlice(timeStamps, startIndex, noOfPoints);
                viewPortDataSeriesA = (double[])Chart.arraySlice(dataSeriesA, startIndex, noOfPoints);
                viewPortDataSeriesB = (double[])Chart.arraySlice(dataSeriesB, startIndex, noOfPoints);

                // Keep track of the latest available data at chart plotting time
                trackLineEndPos = timeStamps[currentIndex - 1];
            }

            //
            // At this stage, we have extracted the visible data. We can use those data to plot the chart.
            //

            //================================================================================
            // Configure overall chart appearance.
            //================================================================================

            // Create an XYChart object of size 640 x 350 pixels
            XYChart c = new XYChart(640, 350);

            // Set the plotarea at (55, 50) with width 85 pixels less than chart width, and height 80 pixels
            // less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky blue (a0c0ff)
            // as background. Set border to transparent and grid lines to white (ffffff).
            c.setPlotArea(55, 50, c.getWidth() - 85, c.getHeight() - 80, c.linearGradientColor(0, 50, 0,
                                                                                               c.getHeight() - 30, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // As the data can lie outside the plotarea in a zoomed chart, we need enable clipping.
            c.setClipping();

            // Add a title to the chart using 18 pts Times New Roman Bold Italic font
            c.addTitle("   Multithreading Real-Time Chart", "Arial", 18);

            // Add a legend box at (55, 25) using horizontal layout. Use 8pts Arial Bold as font. Set the
            // background and border color to Transparent and use line style legend key.
            LegendBox b = c.addLegend(55, 25, false, "Arial Bold", 10);

            b.setBackground(Chart.Transparent);
            b.setLineStyleKey();

            // Set the x and y axis stems to transparent and the label font to 10pt Arial
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);
            c.xAxis().setLabelStyle("Arial", 10);
            c.yAxis().setLabelStyle("Arial", 10);

            // Add axis title using 10pts Arial Bold Italic font
            c.yAxis().setTitle("Ionic Temperature (C)", "Arial Bold", 10);

            //================================================================================
            // Add data to chart
            //================================================================================

            //
            // In this example, we represent the data by lines. You may modify the code below to use other
            // representations (areas, scatter plot, etc).
            //

            // Add a line layer for the lines, using a line width of 2 pixels
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);
            layer.setFastLineMode();

            // Now we add the 3 data series to a line layer, using the color red (ff0000), green (00cc00)
            // and blue (0000ff)
            layer.setXData(viewPortTimeStamps);
            layer.addDataSet(viewPortDataSeriesA, 0xff0000, "Alpha");
            layer.addDataSet(viewPortDataSeriesB, 0x00cc00, "Beta");

            //================================================================================
            // Configure axis scale and labelling
            //================================================================================

            if (currentIndex > 0)
            {
                c.xAxis().setDateScale(viewPortStartDate, viewPortEndDate);
            }

            // For the automatic axis labels, set the minimum spacing to 75/30 pixels for the x/y axis.
            c.xAxis().setTickDensity(75);
            c.yAxis().setTickDensity(30);

            // We use "hh:nn:ss" as the axis label format.
            c.xAxis().setLabelFormat("{value|hh:nn:ss}");

            // We make sure the tick increment must be at least 1 second.
            c.xAxis().setMinTickInc(1);

            // Set the auto-scale margin to 0.05, and the zero affinity to 0.6
            c.yAxis().setAutoScale(0.05, 0.05, 0.6);

            //================================================================================
            // Output the chart
            //================================================================================

            // We need to update the track line too. If the mouse is moving on the chart (eg. if
            // the user drags the mouse on the chart to scroll it), the track line will be updated
            // in the MouseMovePlotArea event. Otherwise, we need to update the track line here.
            if (!WPFChartViewer1.IsInMouseMoveEvent)
            {
                trackLineLabel(c, trackLineIsAtEnd ? c.getWidth() : viewer.PlotAreaMouseX);
            }

            viewer.Chart = c;
        }
Exemplo n.º 20
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}'");
        }
Exemplo n.º 21
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[] 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.Chart = c;

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable");
        }
Exemplo n.º 22
0
        //public void createChart(WinChartViewer viewer, int chartIndex)
        public void drawChart(WinChartViewer viewer, double[] data, int color, bool init)
        {
            int startIndex, endIndex;

            // Get the start date and end date that are visible on the chart.
            DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft));
            DateTime viewPortEndDate   = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft +
                                                                               viewer.ViewPortWidth));

            // Extract the part of the data arrays that are visible.
            DateTime[] viewPortTimeStamps = null;
            double[]   viewPortData       = null;

            if (init == true)
            {
                startIndex = 0;
                endIndex   = data.Length;
            }
            else
            {
                startIndex = (int)Math.Floor(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortStartDate)); //Real Trend
                endIndex   = (int)Math.Ceiling(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortEndDate)); //Real Trend
            }

            int noOfPoints = endIndex - startIndex + 1;

            viewPortTimeStamps = (DateTime[])Chart.arraySlice(timeStamps, startIndex, noOfPoints);
            viewPortData       = (double[])Chart.arraySlice(data, startIndex, noOfPoints);

            XYChart c = new XYChart(776, 197, 0x787878, 0x787878);

            /*            c.setPlotArea(30, 10, c.getWidth() - 40, c.getHeight() - 50,
             *              0x787878, -1, Chart.Transparent,
             *              c.dashLineColor(0xffffff, 0x000303), c.dashLineColor(0xffffff, 0x000303));
             */

            c.setPlotArea(30, 10, c.getWidth() - 40, c.getHeight() - 50, 0x000000, 0x000000, Chart.LineColor, 0xc0c0c0, 0x000000
                          ).setGridWidth(2, 1, 1, 1);

/*            c.setPlotArea(30, 10, c.getWidth() - 40, c.getHeight() - 50, c.linearGradientColor(0, 55, 0,
 *  c.getHeight() - 35, 0xf5f5f5, 0x787878), -1, Chart.Transparent, 0xffffff, 0xffffff);*/

            c.xAxis().setColors(0xffffff, 0xffffff, 0xffffff);
            c.yAxis().setColors(0xffffff, 0xffffff, 0xffffff);

            c.setClipping();

            sb_d.Clear();
            sb_d.AppendFormat("{{value|hh:nn:ss.f}}");

            c.xAxis().setLabelFormat(sb_d.ToString());

            c.setClipping();

            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);
            layer.setFastLineMode();

            layer.setXData(viewPortTimeStamps);
            layer.addDataSet(viewPortData, color, "Heart");

            if (currentIndex > 0)
            {
                c.xAxis().setDateScale(viewPortStartDate, viewPortEndDate);
            }

            //viewer.syncDateAxisWithViewPort("x", c.xAxis());

            c.xAxis().setTickDensity(75);
            c.yAxis().setTickDensity(30);

            c.xAxis().setLabelStep(100);

            c.xAxis().setMinTickInc(1);

            viewer.Chart = c;

            if (viewer.ImageMap == null)
            {
                viewer.ImageMap = viewer.Chart.getHTMLImageMap("", "", "");
            }
        }
Exemplo n.º 23
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 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 18 pts 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, 0x000101), -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 8pts Arial Bold
            c.xAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis2().setLabelStyle("Arial Bold", 8);

            // Add axis title using 10pts 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.makeImage();

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Backlog of {dataSetName} at {x|mm/dd/yyyy}: US$ {value}M'");
        }
        //
        // Draw the chart
        //
        private void drawChart(RazorChartViewer viewer)
        {
            // Determine the visible x-axis range
            DateTime viewPortStartDate = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft))
            ;
            DateTime viewPortEndDate = Chart.NTime(viewer.getValueAtViewPort("x", viewer.ViewPortLeft +
                                                                             viewer.ViewPortWidth));

            // We need to get the data within the visible x-axis range. In real code, this can be by
            // using a database query or some other means as specific to the application. In this demo,
            // we just generate a random data table, and then select the data within the table.
            RanTable r = getRandomTable();

            // Select the data for the visible date range viewPortStartDate to viewPortEndDate. It is
            // possible there is no data point at exactly viewPortStartDate or viewPortEndDate. In this
            // case, we also need the data points that are just outside the visible date range to
            // "overdraw" the line a little bit (the "overdrawn" part will be clipped to the plot area)
            // In this demo, we do this by adding a one day margin to the date range when selecting the
            // data.
            r.selectDate(0, viewPortStartDate.AddDays(-1), viewPortEndDate.AddDays(1));

            // The selected data from the random data table
            DateTime[] timeStamps  = Chart.NTime(r.getCol(0));
            double[]   dataSeriesA = r.getCol(1);
            double[]   dataSeriesB = r.getCol(2);
            double[]   dataSeriesC = r.getCol(3);

            //
            // Now we have obtained the data, we can plot the chart.
            //

            //================================================================================
            // Configure overall chart appearance.
            //================================================================================

            // Create an XYChart object of size 640 x 350 pixels
            XYChart c = new XYChart(640, 350);

            // Set the plotarea at (55, 55) with width 80 pixels less than chart width, and height 90
            // pixels less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky
            // blue (a0c0ff) as background. Set border to transparent and grid lines to white (ffffff).
            c.setPlotArea(55, 55, c.getWidth() - 80, c.getHeight() - 90, c.linearGradientColor(0, 55, 0,
                                                                                               c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // As the data can lie outside the plotarea in a zoomed chart, we need to enable clipping.
            c.setClipping();

            // Add a title to the chart using 18pt Times New Roman Bold Italic font
            c.addTitle("    Zooming and Scrolling with Track Line", "Times New Roman Bold Italic", 18);

            // Set the axis stem to transparent
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);

            // Add axis title using 10pt Arial Bold Italic font
            c.yAxis().setTitle("Ionic Temperature (C)", "Arial Bold Italic", 10);

            //================================================================================
            // Add data to chart
            //================================================================================

            //
            // In this example, we represent the data by lines. You may modify the code below to use
            // other layer types (areas, scatter plot, etc).
            //

            // Add a line layer for the lines, using a line width of 2 pixels
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);

            // In this demo, we do not have too many data points. In real code, the chart may contain a
            // lot of data points when fully zoomed out - much more than the number of horizontal pixels
            // in this plot area. So it is a good idea to use fast line mode.
            layer.setFastLineMode();

            // Add up to 3 data series to a line layer, depending on whether the user has selected the
            // data series.
            layer.setXData(timeStamps);
            if (viewer.GetCustomAttr("data0CheckBox") != "F")
            {
                layer.addDataSet(dataSeriesA, 0xff3333, "Alpha Series");
            }
            if (viewer.GetCustomAttr("data1CheckBox") != "F")
            {
                layer.addDataSet(dataSeriesB, 0x008800, "Beta Series");
            }
            if (viewer.GetCustomAttr("data2CheckBox") != "F")
            {
                layer.addDataSet(dataSeriesC, 0x3333cc, "Gamma Series");
            }

            //================================================================================
            // Configure axis scale and labelling
            //================================================================================

            // Set the x-axis as a date/time axis with the scale according to the view port x range.
            viewer.syncDateAxisWithViewPort("x", c.xAxis());

            //
            // In this demo, the time range can be from a few years to a few days. We demonstrate how to
            // set up different date/time format based on the time range.
            //

            // If all ticks are yearly aligned, then we use "yyyy" as the label format.
            c.xAxis().setFormatCondition("align", 360 * 86400);
            c.xAxis().setLabelFormat("{value|yyyy}");

            // If all ticks are monthly aligned, then we use "mmm yyyy" in bold font as the first label
            // of a year, and "mmm" for other labels.
            c.xAxis().setFormatCondition("align", 30 * 86400);
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "<*font=bold*>{value|mmm yyyy}",
                                     Chart.AllPassFilter(), "{value|mmm}");

            // If all ticks are daily algined, then we use "mmm dd<*br*>yyyy" in bold font as the first
            // label of a year, and "mmm dd" in bold font as the first label of a month, and "dd" for
            // other labels.
            c.xAxis().setFormatCondition("align", 86400);
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(),
                                     "<*block,halign=left*><*font=bold*>{value|mmm dd<*br*>yyyy}", Chart.StartOfMonthFilter(),
                                     "<*font=bold*>{value|mmm dd}");
            c.xAxis().setMultiFormat2(Chart.AllPassFilter(), "{value|dd}");

            // For all other cases (sub-daily ticks), use "hh:nn<*br*>mmm dd" for the first label of a
            // day, and "hh:nn" for other labels.
            c.xAxis().setFormatCondition("else");
            c.xAxis().setMultiFormat(Chart.StartOfDayFilter(), "<*font=bold*>{value|hh:nn<*br*>mmm dd}",
                                     Chart.AllPassFilter(), "{value|hh:nn}");

            //================================================================================
            // Step 5 - Output the chart
            //================================================================================

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

            // Output Javascript chart model to the browser to suppport tracking cursor
            viewer.ChartModel = c.getJsChartModel();
        }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // In this example, we simply use random data for the 2 data series.
            RanSeries r = new RanSeries(127);

            double[]   data0      = r.getSeries(180, 70, -5, 5);
            double[]   data1      = r.getSeries(180, 150, -15, 15);
            DateTime[] timeStamps = r.getDateSeries(180, new DateTime(2014, 3, 1), 86400);

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

            // Set default text color to dark grey (0x333333)
            c.setColor(Chart.TextColor, 0x333333);

            // Add a title box using grey (0x555555) 20pt Arial Bold font
            c.addTitle("   Plasma Stabilizer Energy Usage", "Arial Bold", 20, 0x555555);

            // Set the plotarea at (70, 70) and of size 540 x 320 pixels, with transparent background and
            // border and light grey (0xcccccc) horizontal grid lines
            c.setPlotArea(70, 70, 540, 320, -1, -1, Chart.Transparent, 0xcccccc);

            // Add a legend box with horizontal layout above the plot area at (70, 32). Use 12pt Arial
            // Bold dark grey (0x555555) font, transparent background and border, and line style legend
            // icon.
            LegendBox b = c.addLegend(70, 32, false, "Arial Bold", 12);

            b.setFontColor(0x555555);
            b.setBackground(Chart.Transparent, Chart.Transparent);
            b.setLineStyleKey();

            // Set axis label font to 12pt Arial
            c.xAxis().setLabelStyle("Arial", 12);
            c.yAxis().setLabelStyle("Arial", 12);

            // Set the x and y axis stems to transparent, and the x-axis tick color to grey (0xaaaaaa)
            c.xAxis().setColors(Chart.Transparent, Chart.TextColor, Chart.TextColor, 0xaaaaaa);
            c.yAxis().setColors(Chart.Transparent);

            // Set the major/minor tick lengths for the x-axis to 10 and 0.
            c.xAxis().setTickLength(10, 0);

            // For the automatic axis labels, set the minimum spacing to 80/40 pixels for the x/y axis.
            c.xAxis().setTickDensity(80);
            c.yAxis().setTickDensity(40);

            // Use "mm/yyyy" as the x-axis label format for the first plotted month of a year, and "mm"
            // for other months
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "{value|mm/yyyy} ",
                                     Chart.StartOfMonthFilter(), "{value|mm}");

            // Add a title to the y axis using dark grey (0x555555) 12pt Arial Bold font
            c.yAxis().setTitle("Energy (kWh)", "Arial Bold", 14, 0x555555);

            // Add a line layer with 2-pixel line width
            LineLayer layer0 = c.addLineLayer(data0, 0xcc0000, "Power Usage");

            layer0.setXData(timeStamps);
            layer0.setLineWidth(2);

            // Add an area layer using semi-transparent blue (0x7f0044cc) as the fill color
            AreaLayer layer1 = c.addAreaLayer(data1, 0x7f0044cc, "Effective Load");

            layer1.setXData(timeStamps);
            layer1.setBorderColor(Chart.SameAsMainColor);

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

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "", "title='[{x|mm dd, yyyy}] {value} kWh'");
        }
Exemplo n.º 26
0
        //
        // Draw the chart
        //
        private void drawChart(WPFChartViewer viewer)
        {
            // Have not started collecting data ???
            if (currentIndex <= 0)
            {
                return;
            }

            // The start time is equal to the latest time minus the time range of the chart
            double startTime  = timeStamps[currentIndex - 1] - timeRange;
            int    startIndex = (int)Math.Ceiling(Chart.bSearch(timeStamps, 0, currentIndex, startTime) - 0.1);

            // For a sweep chart, if the line goes beyond the right border, it will wrap back to
            // the left. We need to determine the wrap position (the right border).
            double wrapTime   = Math.Floor(startTime / timeRange + 1) * timeRange;
            double wrapIndex  = Chart.bSearch(timeStamps, 0, currentIndex, wrapTime);
            int    wrapIndexA = (int)Math.Ceiling(wrapIndex);
            int    wrapIndexB = (int)Math.Floor(wrapIndex);

            // The data arrays and the colors and names of the data series
            var allArrays = new[] { timeStamps, channel1, channel2 };

            int[]    colors = { 0xff0000, 0x00cc00 };
            string[] names  = { "Channel 1", "Channel 2" };

            // Split all data arrays into two parts A and B at the wrap position. The B part is the
            // part that is wrapped back to the left.
            var allArraysA = new double[allArrays.Length][];
            var allArraysB = new double[allArrays.Length][];

            for (int i = 0; i < allArrays.Length; ++i)
            {
                allArraysA[i] = (double[])Chart.arraySlice(allArrays[i], startIndex, wrapIndexA - startIndex + 1);
                allArraysB[i] = (double[])Chart.arraySlice(allArrays[i], wrapIndexB, currentIndex - wrapIndexB);
            }

            // Normalize the plotted timeStamps (the first element of allArrays) to start from 0
            for (int i = 0; i < allArraysA[0].Length; ++i)
            {
                allArraysA[0][i] -= wrapTime - timeRange;
            }
            for (int i = 0; i < allArraysB[0].Length; ++i)
            {
                allArraysB[0][i] -= wrapTime;
            }

            //
            // Now we have prepared all the data and can plot the chart.
            //

            //================================================================================
            // Configure overall chart appearance.
            //================================================================================

            // Create an XYChart object the same size as WPFChartViewer, with a minimum of 300 x 150
            XYChart c = new XYChart(Math.Max(300, (int)viewer.ActualWidth), Math.Max(150, (int)viewer.ActualHeight));

            // Set the plotarea at (0, 0) with width 1 pixel less than chart width, and height 20 pixels
            // less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky blue (a0c0ff)
            // as background. Set border to transparent and grid lines to white (ffffff).
            c.setPlotArea(0, 0, c.getWidth() - 1, c.getHeight() - 20, c.linearGradientColor(0, 0, 0,
                                                                                            c.getHeight() - 20, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // In our code, we can overdraw the line slightly, so we clip it to the plot area.
            c.setClipping();

            // Add a legend box at the right side using horizontal layout. Use 10pt Arial Bold as font. Set
            // the background and border color to Transparent and use line style legend key.
            LegendBox b = c.addLegend(c.getWidth() - 1, 10, false, "Arial Bold", 10);

            b.setBackground(Chart.Transparent);
            b.setAlignment(Chart.Right);
            b.setLineStyleKey();

            // Set the x and y axis stems to transparent and the label font to 10pt Arial
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);
            c.xAxis().setLabelStyle("Arial", 10);
            c.yAxis().setLabelStyle("Arial", 10, 0x336699);

            // Configure the y-axis label to be inside the plot area and above the horizontal grid lines
            c.yAxis().setLabelGap(-1);
            c.yAxis().setMargin(20);
            c.yAxis().setLabelAlignment(1);

            // Configure the x-axis labels to be to the left of the vertical grid lines
            c.xAxis().setLabelAlignment(1);

            //================================================================================
            // Add data to chart
            //================================================================================

            // Draw the lines, which consists of A segments and B segments (the wrapped segments)
            foreach (var dataArrays in new[] { allArraysA, allArraysB })
            {
                LineLayer layer = c.addLineLayer2();
                layer.setLineWidth(2);
                layer.setFastLineMode();

                // The first element of dataArrays is the timeStamp, and the rest are the data.
                layer.setXData(dataArrays[0]);
                for (int i = 1; i < dataArrays.Length; ++i)
                {
                    layer.addDataSet(dataArrays[i], colors[i - 1], names[i - 1]);
                }

                // Disable legend entries for the B lines to avoid duplication with the A lines
                if (dataArrays == allArraysB)
                {
                    layer.setLegend(Chart.NoLegend);
                }
            }

            // The B segments contain the latest data. We add a vertical line at the latest position.
            int  lastIndex = allArraysB[0].Length - 1;
            Mark m         = c.xAxis().addMark(allArraysB[0][lastIndex], -1);

            m.setMarkColor(0x0000ff, Chart.Transparent, Chart.Transparent);
            m.setDrawOnTop(false);

            // We also add a symbol and a label for each data series at the latest position
            for (int i = 1; i < allArraysB.Length; ++i)
            {
                // Add the symbol
                Layer layer = c.addScatterLayer(new double[] { allArraysB[0][lastIndex] }, new double[] {
                    allArraysB[i][lastIndex]
                }, "", Chart.CircleSymbol, 9, colors[i - 1], colors[i - 1]);
                layer.moveFront();

                // Add the label
                string label = "<*font,bgColor=" + colors[i - 1].ToString("x") + "*> {value|P4} <*/font*>";
                layer.setDataLabelFormat(label);

                // The label style
                ChartDirector.TextBox t = layer.setDataLabelStyle("Arial Bold", 10, 0xffffff);
                bool isOnLeft           = allArraysB[0][lastIndex] <= timeRange / 2;
                t.setAlignment(isOnLeft ? Chart.Left : Chart.Right);
                t.setMargin(isOnLeft ? 5 : 0, isOnLeft ? 0 : 5, 0, 0);
            }

            //================================================================================
            // Configure axis scale and labelling
            //================================================================================

            c.xAxis().setLinearScale(0, timeRange);

            // For the automatic axis labels, set the minimum spacing to 75/40 pixels for the x/y axis.
            c.xAxis().setTickDensity(75);
            c.yAxis().setTickDensity(40);

            // Set the auto-scale margin to 0.05, and the zero affinity to 0.6
            c.yAxis().setAutoScale(0.05, 0.05, 0.6);

            //================================================================================
            // Output the chart
            //================================================================================

            viewer.Chart = c;
        }
Exemplo n.º 27
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)
        {
            //
            //    We use a random table to simulate generating 12 months of data
            //

            // Create the random table object with 4 cols * 12 rows, using 3 as seed
            RanTable rantable = new RanTable(3, 4, 12);

            // Set the 1st column to be the 12 months of year 2002
            rantable.setDateCol(0, new DateTime(2002, 1, 1), 86400 * 30);

            // Set the 2nd, 3rd and 4th columns to be random numbers starting from
            // 125, 75, and 100 respectively. The change between rows is set to -35
            // to + 35. The minimum value of any cell is 0.
            rantable.setCol(1, 125, -35, 35, 0);
            rantable.setCol(2, 75, -35, 35, 0);
            rantable.setCol(3, 100, -35, 35, 0);

            // Get the 1st column (time) as the x data
            double[] dataX = rantable.getCol(0);

            // Get the 2nd, 3rd and 4th columns as 3 data sets
            double[] dataY0 = rantable.getCol(1);
            double[] dataY1 = rantable.getCol(2);
            double[] dataY2 = rantable.getCol(3);

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

            // Add a title to the chart
            c.addTitle("<*underline=2*>Rotated Line Chart Demo",
                       "Times New Roman Bold Italic", 14);

            // Set the plotarea at (60, 75) and of size 190 x 320 pixels. Turn on
            // both horizontal and vertical grid lines with light grey color
            // (0xc0c0c0)
            c.setPlotArea(60, 75, 190, 320).setGridColor(0xc0c0c0, 0xc0c0c0);

            // Add a legend box at (270, 75)
            c.addLegend(270, 75);

            // Swap the x and y axis to become a rotated chart
            c.swapXY();

            // Set the y axis on the top side (right + rotated = top)
            c.setYAxisOnRight();

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

            // Reverse the x axis so it is pointing downwards
            c.xAxis().setReverse();

            // Add a line chart layer using the given data
            LineLayer layer = c.addLineLayer2();

            layer.setXData(dataX);
            layer.addDataSet(dataY0, 0xff0000, "Server A");
            layer.addDataSet(dataY1, 0x338033, "Server B");
            layer.addDataSet(dataY2, 0x0000ff, "Server C");

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

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

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='[{dataSetName}] {x|mm/yyyy}: {value|0} MByte'");
        }
Exemplo n.º 28
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // The data for the line 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, 91 };

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

            // Create a XYChart object of size 500 x 320 pixels, with a pale purpule (0xffccff)
            // background, a black border, and 1 pixel 3D border effect.
            XYChart c = new XYChart(500, 320, 0xffccff, 0x000000, 1);

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

            // Add a legend box at (55, 25) (top of the chart) with horizontal layout. Use 8pt Arial
            // font. Set the background and border color to Transparent.
            c.addLegend(55, 22, false, "", 8).setBackground(Chart.Transparent);

            // Add a title box to the chart using 13pt Times Bold Italic font. The text is white
            // (0xffffff) on a purple (0x800080) background, with a 1 pixel 3D border.
            c.addTitle("Long Term Server Load", "Times New Roman Bold Italic", 13, 0xffffff
                       ).setBackground(0x800080, -1, 1);

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

            // Set the labels on the x axis. Rotate the font by 90 degrees.
            c.xAxis().setLabels(labels).setFontAngle(90);

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

            // Add the data to the line layer using light brown color (0xcc9966) with a 7 pixel square
            // symbol
            lineLayer.addDataSet(data, 0xcc9966, "Server Utilization").setDataSymbol(Chart.SquareSymbol,
                                                                                     7);

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

            // tool tip for the line layer
            lineLayer.setHTMLImageMap("", "", "title='{xLabel}: {value} MBytes'");

            // Add a trend line layer using the same data with a dark green (0x008000) color. Set the
            // line width to 2 pixels
            TrendLayer trendLayer = c.addTrendLayer(data, 0x008000, "Trend Line");

            trendLayer.setLineWidth(2);

            // tool tip for the trend layer
            trendLayer.setHTMLImageMap("", "", "title='Change rate: {slope|2} MBytes/per month'");

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

            // include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("");
        }
Exemplo n.º 29
0
        //
        // Draw the chart.
        //
        private void drawChart(WinChartViewer viewer)
        {
            // Get the start date and end date that are visible on the chart.
            double viewPortStartDate = viewer.getValueAtViewPort("x", viewer.ViewPortLeft);
            double viewPortEndDate   = viewer.getValueAtViewPort("x", viewer.ViewPortLeft +
                                                                 viewer.ViewPortWidth);

            // Extract the part of the data arrays that are visible.
            double[] viewPortTimeStamps  = null;
            double[] viewPortDataSeriesA = null;
            double[] viewPortDataSeriesB = null;

            if (currentIndex > 0)
            {
                // Get the array indexes that corresponds to the visible start and end dates
                int startIndex = (int)Math.Floor(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortStartDate));
                int endIndex   = (int)Math.Ceiling(Chart.bSearch2(timeStamps, 0, currentIndex, viewPortEndDate));
                int noOfPoints = endIndex - startIndex + 1;

                // Extract the visible data
                viewPortTimeStamps  = (double[])Chart.arraySlice(timeStamps, startIndex, noOfPoints);
                viewPortDataSeriesA = (double[])Chart.arraySlice(dataSeriesA, startIndex, noOfPoints);
                viewPortDataSeriesB = (double[])Chart.arraySlice(dataSeriesB, startIndex, noOfPoints);
                chartTimeLimit      = timeStamps[currentIndex - 1];
            }

            //
            // At this stage, we have extracted the visible data. We can use those data to plot the chart.
            //

            //================================================================================
            // Configure overall chart appearance.
            //================================================================================

            // Create an XYChart object of size 640 x 350 pixels
            XYChart c = new XYChart(640, 350);

            // Set the position, size and colors of the plot area
            c.setPlotArea(23, 33, c.getWidth() - 41, c.getHeight() - 53, c.linearGradientColor(0, 33, 0,
                                                                                               c.getHeight() - 53, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // As the data can lie outside the plotarea in a zoomed chart, we need enable clipping.
            c.setClipping();

            // Add a title to the chart using 18 pts Arial font
            c.addTitle("Real-Time Chart with Measurement Cursors", "Arial", 18);

            // Add a legend box at (60, 28) using horizontal layout. Use 8pts Arial Bold as font. Set the
            // background and border color to Transparent and use line style legend key.
            LegendBox b = c.addLegend(60, 28, false, "Arial Bold", 10);

            b.setBackground(Chart.Transparent);
            b.setLineStyleKey();

            // Set the x and y axis stems to transparent and the label font to 10pt Arial
            c.xAxis().setColors(Chart.Transparent);
            c.yAxis().setColors(Chart.Transparent);
            c.xAxis().setLabelStyle("Arial", 10);
            c.yAxis().setLabelStyle("Arial Bold", 10, 0x336699);

            // Set the y-axis tick length to 0 to disable the tick and put the labels closer to the axis.
            c.yAxis().setLabelGap(-1);
            c.yAxis().setLabelAlignment(1);
            c.yAxis().setTickLength(0);
            c.yAxis().setMargin(20);

            // Add axis title using 12pts Arial Bold Italic font
            c.yAxis().setTitle("Ionic Temperature (C)", "Arial Bold", 12);

            // Configure the x-axis tick length to 1 to put the labels closer to the axis.
            c.xAxis().setTickLength(1);

            //================================================================================
            // Add data to chart
            //================================================================================

            //
            // In this example, we represent the data by lines. You may modify the code below to use other
            // representations (areas, scatter plot, etc).
            //

            // Add a line layer for the lines, using a line width of 2 pixels
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);
            layer.setFastLineMode();

            // Now we add the 3 data series to a line layer, using the color red (ff0000), green (00cc00)
            // and blue (0000ff)
            layer.setXData(viewPortTimeStamps);
            layer.addDataSet(viewPortDataSeriesA, 0x00cc00, "Alpha");
            layer.addDataSet(viewPortDataSeriesB, 0x0000ff, "Beta");

            //================================================================================
            // Configure axis scale and labelling
            //================================================================================

            if (currentIndex > 0)
            {
                c.xAxis().setDateScale(viewPortStartDate, viewPortEndDate);
            }

            // For the automatic axis labels, set the minimum spacing to 75/30 pixels for the x/y axis.
            c.xAxis().setTickDensity(75);
            c.yAxis().setTickDensity(30);

            // We use "hh:nn:ss" as the axis label format.
            c.xAxis().setLabelFormat("{value|nn:ss}");

            // We make sure the tick increment must be at least 1 second.
            c.xAxis().setMinTickInc(1);

            //================================================================================
            // Output the chart
            //================================================================================

            // We need to update the track line too.
            trackLineLabel(c);

            // Set the chart image to the WinChartViewer
            viewer.Chart = c;
        }
Exemplo n.º 30
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[] 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'");
        }