//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)
        {
            // Sample data for the Box-Whisker chart. Represents the minimum, 1st quartile, medium,
            // 3rd quartile and maximum values of some quantities
            double[] Q0Data = { 40, 45, 40, 30, 20, 50, 25, 44 };
            double[] Q1Data = { 55, 60, 50, 40, 38, 60, 51, 60 };
            double[] Q2Data = { 62, 70, 60, 50, 48, 70, 62, 70 };
            double[] Q3Data = { 70, 80, 65, 60, 53, 78, 69, 76 };
            double[] Q4Data = { 80, 90, 75, 70, 60, 85, 80, 84 };

            // The labels for the chart
            string[] labels = { "A", "B", "C", "D", "E", "F", "G", "H" };

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

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

            // Add a title box using grey (0x555555) 18pt Arial font
            ChartDirector.TextBox title = c.addTitle("     Pattern Recognition Accuracy", "Arial",
                                                     18, 0x555555);

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

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

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

            // Add a box whisker layer using light blue (0x99ccee) for the fill color and blue
            // (0x6688aa) for the whisker color. Set line width to 2 pixels. Use rounded corners and
            // bar lighting effect.
            BoxWhiskerLayer b = c.addBoxWhiskerLayer(Q3Data, Q1Data, Q4Data, Q0Data, Q2Data,
                                                     0x99ccee, 0x6688aa);

            b.setLineWidth(2);
            b.setRoundedCorners();
            b.setBorderColor(Chart.Transparent, Chart.barLighting());

            // Adjust the plot area to fit under the title with 10-pixel margin on the other three
            // sides.
            c.packPlotArea(10, title.getHeight(), c.getWidth() - 10, c.getHeight() - 10);

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='[{xLabel}] min/med/max = {min}/{med}/{max}\nInter-quartile range: " +
                                                "{bottom} to {top}'");
        }
Esempio n. 2
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)
        {
            // Sample data for the Box-Whisker chart. Represents the minimum, 1st
            // quartile, medium, 3rd quartile and maximum values of some quantities
            double[] Q0Data = { 40, 45, 40, 30, 20, 50, 25, 44 };
            double[] Q1Data = { 55, 60, 50, 40, 38, 60, 51, 60 };
            double[] Q2Data = { 62, 70, 60, 50, 48, 70, 62, 70 };
            double[] Q3Data = { 70, 80, 65, 60, 53, 78, 69, 76 };
            double[] Q4Data = { 80, 90, 75, 70, 60, 85, 80, 84 };

            // The labels for the chart
            string[] labels = { "Group A", "Group B", "Group C", "Group D", "Group E",
                                "Group F", "Group G", "Group H" };

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

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

            // Add a title to the chart
            c.addTitle("Computer Vision Test Scores");

            // Set the labels on the x axis and the font to Arial Bold
            c.xAxis().setLabels(labels).setFontStyle("Arial Bold");

            // Set the font for the y axis labels to Arial Bold
            c.yAxis().setLabelStyle("Arial Bold");

            // Add a Box Whisker layer using light blue 0x9999ff as the fill color
            // and blue (0xcc) as the line color. Set the line width to 2 pixels
            c.addBoxWhiskerLayer(Q3Data, Q1Data, Q4Data, Q0Data, Q2Data, 0x9999ff,
                                 0x0000cc).setLineWidth(2);

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

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{xLabel}: min/med/max = {min}/{med}/{max}\nInter-quartile " +
                                                "range: {bottom} to {top}'");
        }
Esempio n. 3
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the bars and the marks
            double[] barData  = { 100, 125, 245, 147, 67, 96, 160, 145, 97, 167, 220, 125 };
            double[] markData = { 85, 156, 220, 120, 80, 110, 140, 130, 111, 180, 175, 100 };

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

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

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

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

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

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

            legendBox.setAlignment(Chart.BottomCenter);

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Output the chart
            viewer.Chart = c;

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable");
        }
        //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 gantt chart, representing the start date, end date and names for various
            // activities
            DateTime[] startDate = { new DateTime(2004,  8, 16), new DateTime(2004,  8, 30),
                                     new DateTime(2004,  9, 13), new DateTime(2004,  9, 20),new DateTime(2004,   9, 27),
                                     new DateTime(2004, 10,  4), new DateTime(2004, 10, 25),new DateTime(2004,  11,  1),
                                     new DateTime(2004, 11, 8) };
            DateTime[] endDate = { new DateTime(2004,  8, 30), new DateTime(2004,  9, 13),
                                   new DateTime(2004,  9, 27), new DateTime(2004, 10,  4),new DateTime(2004,  10, 11),
                                   new DateTime(2004, 11,  8), new DateTime(2004, 11,  8),new DateTime(2004,  11, 22),
                                   new DateTime(2004, 11, 22) };
            string[]   labels = { "Market Research", "Define Specifications", "Overall Archiecture",
                                  "Project Planning",  "Detail Design",         "Software Development","Test Plan",
                                  "Testing and QA",    "User Documentation" };

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

            // Add a title to the chart using 15 points Times Bold Itatic font, with white (ffffff)
            // text on a deep blue (000080) background
            c.addTitle("Simple Gantt Chart Demo", "Times New Roman Bold Italic", 15, 0xffffff
                       ).setBackground(0x000080);

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

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

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

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

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

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

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

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

            // Add a green (33ff33) box-whisker layer showing the box only.
            c.addBoxWhiskerLayer(Chart.CTime(startDate), Chart.CTime(endDate), null, null, null,
                                 0x00cc00, Chart.SameAsMainColor, Chart.SameAsMainColor);

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{xLabel}: {top|mmm dd, yyyy} to {bottom|mmm dd, yyyy}'");
        }
        //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'");
        }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // 4 data points to represent the cash flow for the Q1 - Q4
            double[] data = { 230, -140, 220, 330 };

            // We want to plot a waterfall chart showing the 4 quarters as well as the total
            string[] labels = { "1st Quarter", "2nd Quarter", "3rd Quarter", "4th Quarter", "Total" };

            // The top side of the bars in a waterfall chart is the accumulated data. We use the
            // ChartDirector ArrayMath utility to accumulate the data. The "total" is handled by
            // inserting a zero point at the end before accumulation (after accumulation it will become
            // the total).
            double[] boxTop = new ArrayMath(data).insert2(0, 1, data.Length).acc().result();

            // The botom side of the bars is just the top side of the previous bar. So we shifted the top
            // side data to obtain the bottom side data.
            double[] boxBottom = new ArrayMath(boxTop).shift(1, 0).result();

            // The last point (total) is different. Its bottom side is always 0.
            boxBottom[boxBottom.Length - 1] = 0;

            // In this example, we want to use different colors depending on the data is positive or
            // negative.
            int posColor = 0x00ff00;
            int negColor = 0xff0000;

            // Create a XYChart object of size 500 x 280 pixels. Set background color to light blue
            // (ccccff), with 1 pixel 3D border effect.
            XYChart c = new XYChart(500, 300, 0xccccff, 0x000000, 1);

            // Add a title to the chart using 13 points Arial Bold Itatic font, with white (ffffff) text
            // on a deep blue (0x80) background
            c.addTitle("Corporate Cash Flow - Year 2004", "Arial Bold Italic", 13, 0xffffff
                       ).setBackground(0x000080);

            // Set the plotarea at (55, 50) and of size 430 x 215 pixels. Use alternative white/grey
            // background.
            c.setPlotArea(55, 50, 430, 215, 0xffffff, 0xeeeeee);

            // Add a legend box at (55, 25) using 8pt Arial Bold font with horizontal layout, with
            // transparent background and border color.
            LegendBox b = c.addLegend(55, 25, false, "Arial Bold", 8);

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

            // Add keys to show the colors for positive and negative cash flows
            b.addKey("Positive Cash Flow", posColor);
            b.addKey("Negative Cash Flow", negColor);

            // Set the labels on the x axis using Arial Bold font
            c.xAxis().setLabels(labels).setFontStyle("Arial Bold");

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

            // Use Arial Bold as the y axis label font
            c.yAxis().setLabelStyle("Arial Bold");

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

            // Add a box-whisker layer to represent the waterfall bars
            BoxWhiskerLayer layer = c.addBoxWhiskerLayer(boxTop, boxBottom);

            // Color the bars depending on whether it is positive or negative
            for (int i = 0; i < boxTop.Length; ++i)
            {
                if (boxTop[i] >= boxBottom[i])
                {
                    layer.setBoxColor(i, posColor);
                }
                else
                {
                    layer.setBoxColor(i, negColor);
                }
            }

            // Put data labels on the bars to show the cash flow using Arial Bold font
            layer.setDataLabelFormat("{={top}-{bottom}}M");
            layer.setDataLabelStyle("Arial Bold").setAlignment(Chart.Center);

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

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "", "title='{xLabel}: {={top}-{bottom}} millions'");
        }