Beispiel #1
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 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.Image = c.makeImage();

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable");
        }
        public void createChart(WinChartViewer viewer, double[] data, string img)
        {
            // The data for the chart
            Chart.setLicenseCode("DEVP-2LSU-B4LX-YCTY-2DF2-77EE");
            //double[] data = {16, 15, 9.7, 5.2, 3};

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

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

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

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

            c.setBorder(10);

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

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

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

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

            //LineLayer lineLayer = c.addLineLayer2();

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

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

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

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

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

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

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

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

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

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

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

            // Output the chart
            viewer.Chart = c;
        }
Beispiel #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)
        {
            //
            // This example demonstrates creating a histogram with a bell curve from raw data. About
            // half of the code is to sort the raw data into slots and to generate the points on the
            // bell curve. The remaining half of the code is the actual charting code.
            //

            // Generate a random guassian distributed data series as the input data for this
            // example.
            RanSeries r = new RanSeries(66);

            double[] samples = r.getGaussianSeries(200, 100, 10);

            //
            // Classify the numbers into slots. In this example, the slot width is 5 units.
            //
            int slotSize = 5;

            // Compute the min and max values, and extend them to the slot boundary.
            ArrayMath m    = new ArrayMath(samples);
            double    minX = Math.Floor(m.min() / slotSize) * slotSize;
            double    maxX = Math.Floor(m.max() / slotSize) * slotSize + slotSize;

            // We can now determine the number of slots
            int slotCount = (int)((maxX - minX + 0.5) / slotSize);

            double[] frequency = new double[slotCount];

            // Count the data points contained in each slot
            for (int i = 0; i < samples.Length; ++i)
            {
                int slotIndex = (int)((samples[i] - minX) / slotSize);
                frequency[slotIndex] = frequency[slotIndex] + 1;
            }

            //
            // Compute Normal Distribution Curve
            //

            // The mean and standard deviation of the data
            double mean   = m.avg();
            double stdDev = m.stdDev();

            // The normal distribution curve (bell curve) is a standard statistics curve. We need to
            // vertically scale it to make it proportion to the frequency count.
            double scaleFactor = slotSize * samples.Length / stdDev / Math.Sqrt(6.2832);

            // In this example, we plot the bell curve up to 3 standard deviations.
            double stdDevWidth = 3;

            // We generate 4 points per standard deviation to be joined with a spline curve.
            int bellCurveResolution = (int)(stdDevWidth * 4 + 1);

            double[] bellCurve = new double[bellCurveResolution];
            for (int i = 0; i < bellCurve.Length; ++i)
            {
                double z = (2 * i - (bellCurve.Length - 1)) * stdDevWidth / (bellCurve.Length - 1);
                bellCurve[i] = Math.Exp(-z * z / 2) * scaleFactor;
            }

            //
            // At this stage, we have obtained all data and can plot the chart.
            //

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

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

            // Display the mean and standard deviation on the chart

            c.addTitle("Mean = " + c.formatValue(mean, "{value|1}") + ", Standard Deviation = " +
                       c.formatValue(stdDev, "{value|2}"), "Arial");


            // Set the x and y 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
            // (0x888888)
            c.xAxis().setColors(Chart.Transparent, Chart.TextColor, Chart.TextColor, 0x888888);
            c.yAxis().setColors(Chart.Transparent);

            // Draw the bell curve as a spline layer in red (0xdd0000) with 2-pixel line width
            SplineLayer bellLayer = c.addSplineLayer(bellCurve, 0xdd0000);

            bellLayer.setXData2(mean - stdDevWidth * stdDev, mean + stdDevWidth * stdDev);
            bellLayer.setLineWidth(2);
            // No tooltip is needed for the spline layer
            bellLayer.setHTMLImageMap("{disable}");

            // Draw the histogram as bars in blue (0x6699bb) with dark blue (0x336688) border
            BarLayer histogramLayer = c.addBarLayer(frequency, 0x6699bb);

            histogramLayer.setBorderColor(0x336688);
            // The center of the bars span from minX + half_bar_width to maxX - half_bar_width
            histogramLayer.setXData2(minX + slotSize / 2.0, maxX - slotSize / 2.0);
            // Configure the bars to touch each other with no gap in between
            histogramLayer.setBarGap(Chart.TouchBar);
            // Use rounded corners for decoration
            histogramLayer.setRoundedCorners();
            // Tool tip for the histogram
            histogramLayer.setHTMLImageMap("", "", "title='{value}'");

            // ChartDirector by default will extend the x-axis scale by 0.5 unit to cater for the
            // bar width. It is because a bar plotted at x actually occupies (x +/- half_bar_width),
            // and the bar width is normally 1 for label based x-axis. However, this chart is using
            // a linear x-axis instead of label based. So we disable the automatic extension and add
            // a dummy layer to extend the x-axis scale to cover minX to maxX.
            c.xAxis().setIndent(false);
            c.addLineLayer2().setXData(minX, maxX);

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

            // Output the chart
            viewer.Chart = c;

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable");
        }
Beispiel #4
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  = { 410, 420, 500, 590 };
            double[] data1  = { 500, 370, 680, 850 };
            string[] labels = { "Q1", "Q2", "Q3", "Q4" };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Revenue in {xLabel} {dataSetName}: US$ {value}M'");
        }
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the bar chart
            double[] data0  = { 100, 125, 245, 147, 67 };
            double[] data1  = { 85, 156, 179, 211, 123 };
            double[] data2  = { 97, 87, 56, 267, 157 };
            string[] labels = { "Mon", "Tue", "Wed", "Thur", "Fri" };

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

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

            // Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical gradient
            // color from light red (ffdddd) to dark red (880000) as background. Set border and grid
            // lines to white (ffffff).
            c.setPlotArea(50, 55, 440, 280, c.linearGradientColor(0, 55, 0, 335, 0xffdddd, 0x880000
                                                                  ), -1, 0xffffff, 0xffffff);

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

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

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

            // Set axis label style to 8pt 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
            c.yAxis().setTitle("Throughput (MBytes Per Hour)");

            // Add a multi-bar layer with 3 data sets and 4 pixels 3D depth
            BarLayer layer = c.addBarLayer2(Chart.Side, 4);

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

            // Set bar border to transparent. Use soft lighting effect with light direction from
            // top.
            layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Top));

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

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} on {xLabel}: {value} MBytes/hour'");
        }
        //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 age groups
            string[] labels = { "0 - 4",   "5 - 9",   "10 - 14", "15 - 19", "20 - 24", "24 - 29",
                                "30 - 34", "35 - 39", "40 - 44", "44 - 49", "50 - 54", "55 - 59","60 - 64",
                                "65 - 69", "70 - 74", "75 - 79", "80+" };

            // The male population (in thousands)
            double[] male = { 215, 238, 225, 236, 235, 260, 286, 340, 363, 305, 259, 164, 135, 127,
                              102,  68, 66 };

            // The female population (in thousands)
            double[] female = { 194, 203, 201, 220, 228, 271, 339, 401, 384, 304, 236, 137, 116, 122,
                                112,  85, 110 };


            //=============================================================
            //    Draw the right bar chart
            //=============================================================

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

            // Set the plotarea at (50, 0) and of size 250 x 255 pixels. Use pink (0xffdddd) as the
            // background.
            c.setPlotArea(50, 0, 250, 255, 0xffdddd);

            // Add a custom text label at the top right corner of the right bar chart
            c.addText(300, 0, "Female", "Times New Roman Bold Italic", 12, 0xa07070).setAlignment(
                Chart.TopRight);

            // Add the pink (0xf0c0c0) bar chart layer using the female data
            BarLayer femaleLayer = c.addBarLayer(female, 0xf0c0c0, "Female");

            // Swap the axis so that the bars are drawn horizontally
            c.swapXY(true);

            // Set the bar to touch each others
            femaleLayer.setBarGap(Chart.TouchBar);

            // Set the border style of the bars to 1 pixel 3D border
            femaleLayer.setBorderColor(-1, 1);

            // Add a Transparent line layer to the chart using the male data. As it is Transparent,
            // only the female bar chart can be seen. We need to put both male and female data in
            // both left and right charts, because we want auto-scaling to produce the same scale
            // for both chart.
            c.addLineLayer(male, Chart.Transparent);

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

            // Set the labels between the two bar charts, which can be considered as the x-axis
            // labels for the right chart
            ChartDirector.TextBox tb = c.xAxis().setLabels(labels);

            // Use a fix width of 50 for the labels (height = automatic) with center alignment
            tb.setSize(50, 0);
            tb.setAlignment(Chart.Center);

            // Set the label font to Arial Bold
            tb.setFontStyle("Arial Bold");

            // Disable ticks on the x-axis by setting the tick length to 0
            c.xAxis().setTickLength(0);

            //=============================================================
            //    Draw the left bar chart
            //=============================================================

            // Create a XYChart object of size 280 x 300 pixels with a transparent background.
            XYChart c2 = new XYChart(280, 300, Chart.Transparent);

            // Set the plotarea at (20, 0) and of size 250 x 255 pixels. Use pale blue (0xddddff) as
            // the background.
            c2.setPlotArea(20, 0, 250, 255, 0xddddff);

            // Add a custom text label at the top left corner of the left bar chart
            c2.addText(20, 0, "Male", "Times New Roman Bold Italic", 12, 0x7070a0);

            // Add the pale blue (0xaaaaff) bar chart layer using the male data
            BarLayer maleLayer = c2.addBarLayer(male, 0xaaaaff, "Male");

            // Swap the axis so that the bars are drawn horizontally
            c2.swapXY(true);

            // Reverse the direction of the y-axis so it runs from right to left
            c2.yAxis().setReverse();

            // Set the bar to touch each others
            maleLayer.setBarGap(Chart.TouchBar);

            // Set the border style of the bars to 1 pixel 3D border
            maleLayer.setBorderColor(-1, 1);

            // Add a Transparent line layer to the chart using the female data. As it is
            // Transparent, only the male bar chart can be seen. We need to put both male and female
            // data in both left and right charts, because we want auto-scaling to produce the same
            // scale for both chart.
            c2.addLineLayer(female, Chart.Transparent);

            // Set the y axis label font to Arial Bold
            c2.yAxis().setLabelStyle("Arial Bold");

            // Set the x-axis labels for tool tip purposes.
            c2.xAxis().setLabels(labels);

            // Hide the x-axis labels by setting them to Transparent. We only need to display the
            // x-axis labels for the right chart.
            c2.xAxis().setColors(0x000000, Chart.Transparent, -1, Chart.Transparent);

            //=============================================================
            //    Use a MultiChart to contain both bar charts
            //=============================================================

            // Create a MultiChart object of size 590 x 320 pixels.
            MultiChart m = new MultiChart(590, 320);

            // Add a title to the chart using Arial Bold Italic font
            m.addTitle("Demographics Hong Kong Year 2002", "Arial Bold Italic");

            // Add another title at the bottom using Arial Bold Italic font
            m.addTitle2(Chart.Bottom, "Population (in thousands)", "Arial Bold Italic", 10);

            // Put the right chart at (270, 25)
            m.addChart(270, 25, c);

            // Put the left chart at (0, 25)
            m.addChart(0, 25, c2);

            // Output the chart
            viewer.Chart = m;

            //include tool tip for the chart
            viewer.ImageMap = m.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} (Age {xLabel}): Population {value}K'");
        }
        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");
        }
Beispiel #8
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // The data for the bar chart
            double[] data0 = { 100, 125, 245, 147, 67 };
            double[] data1 = { 85, 156, 179, 211, 123 };
            double[] data2 = { 97, 87, 56, 267, 157 };

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

            // Create a XYChart object of size 500 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(500, 320);

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

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

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

            // Tentatively set the plotarea to 50 pixels from the left edge, and to just under the title.
            // Set the width to 60% of the chart width, and the height to 50 pixels from the bottom edge.
            // Use pale blue (e8f0f8) background, transparent border, and grey (aaaaaa) grid lines.
            c.setPlotArea(50, title.getHeight(), c.getWidth() * 6 / 10, c.getHeight() - title.getHeight()
                          - 50, 0xe8f0f8, -1, Chart.Transparent, 0xaaaaaa);

            // Add a legend box where the top-right corner is anchored at 10 pixels from the right edge,
            // and just under the title. Use vertical layout and 8 points Arial font.
            LegendBox legendBox = c.addLegend(c.getWidth() - 10, title.getHeight(), true, "Arial", 8);

            legendBox.setAlignment(Chart.TopRight);

            // Set the legend box background and border to transparent
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);

            // Set the legend box icon size to 16 x 32 pixels to match with custom icon size
            legendBox.setKeySize(16, 32);

            // 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 percentage bar layer
            BarLayer layer = c.addBarLayer2(Chart.Percentage);

            // Add the three data sets to the bar layer, using icons images with labels as data set names
            layer.addDataSet(data0, 0x66aaee,
                             "<*block,valign=absmiddle*><*img=service.png*> Service<*/*>");
            layer.addDataSet(data1, 0xeebb22,
                             "<*block,valign=absmiddle*><*img=software.png*> Software<*/*>");
            layer.addDataSet(data2, 0xcc88ff,
                             "<*block,valign=absmiddle*><*img=computer.png*> Hardware<*/*>");

            // Use soft lighting effect with light direction from top
            layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Top));

            // Enable data label at the middle of the the bar
            layer.setDataLabelStyle().setAlignment(Chart.Center);

            // For a vertical stacked chart with positive data only, the last data set is always on top.
            // However, in a vertical legend box, the last data set is at the bottom. This can be
            // reversed by using the setLegend method.
            layer.setLegend(Chart.ReverseLegend);

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

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

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "",
                                                "title='{dataSetName} revenue on {xLabel}: US${value}K ({percent}%)'");
        }
Beispiel #9
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[] data = { 40, 45, 37, 24, 32, 39, 53, 52, 63, 49, 46, 40, 54, 50,
                              57, 57, 48, 49, 63, 67, 74, 72, 70, 89, 74 };
            string[] labels = { "0\nJun 4", "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",
                                "9",        "10", "11", "12", "13", "14", "15", "16", "17","18","19",
                                "20",       "21", "22", "23", "0\nJun 5" };

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

            // Set the plotarea at (80, 60) and of size 300 x 200 pixels. Turn off
            // the grid lines by setting their colors to Transparent.
            c.setPlotArea(80, 28, 300, 200).setGridColor(Chart.Transparent);

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

            // Set the y axis title upright (font angle = 0)
            textbox.setFontAngle(0);

            // Put the y axis title on top of the axis
            textbox.setAlignment(Chart.TopLeft2);

            // Add green (0x99ff99), yellow (0xffff99) and red (0xff9999) zones to
            // the y axis to represent the ranges 0 - 50, 50 - 80, and 80 - max.
            c.yAxis().addZone(0, 50, 0x99ff99);
            c.yAxis().addZone(50, 80, 0xffff99);
            c.yAxis().addZone(80, 9999, 0xff9999);

            // Add a purple (0x800080) mark at y = 70 using a line width of 2.
            c.yAxis().addMark(70, 0x800080, "Alert = 70").setLineWidth(2);

            // Add a green (0x008000) mark at y = 40 using a line width of 2.
            c.yAxis().addMark(40, 0x008000, "Watch = 40").setLineWidth(2);

            // Add a legend box at (165, 0) (top right of the chart) using 8 pts
            // Arial font. and horizontal layout.
            LegendBox legend = c.addLegend(165, 0, false, "Arial Bold", 8);

            // Disable the legend box boundary by setting the colors to Transparent
            legend.setBackground(Chart.Transparent, Chart.Transparent);

            // Add 3 custom entries to the legend box to represent the 3 zones
            legend.addKey("Normal", 0x80ff80);
            legend.addKey("Warning", 0xffff80);
            legend.addKey("Critical", 0xff8080);

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

            // Add a 3D bar layer with the given data
            BarLayer layer = c.addBarLayer(data, 0xbbbbff);

            // Set the bar gap to 0 so that the bars are packed tightly
            layer.setBarGap(0);

            // Set the border color of the bars same as the fill color, with 1 pixel
            // 3D border effect.
            layer.setBorderColor(Chart.SameAsMainColor, 1);

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

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Temperature at {x}:00 = {value} C'");
        }
        //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 bar chart
            double[] data0 = { 44, 55, 100 };
            double[] data1 = { 97, 87, 167 };
            double[] data2 = { 156, 78, 147 };
            double[] data3 = { 125, 118, 211 };

            // The labels for the bar chart. The labels contains embedded images as icons.
            string[] labels = { "<*img=@/images/service.png*><*br*>Service",
                                "<*img=@/images/software.png*><*br*>Software",
                                "<*img=@/images/computer.png*><*br*>Hardware" };

            // Create a XYChart object of size 600 x 350 pixels, using 0xe0e0ff as the background
            // color, 0xccccff as the border color, with 1 pixel 3D border effect.
            XYChart c = new XYChart(600, 350, 0xe0e0ff, 0xccccff, 1);

            // Add a title to the chart using 14 points Times Bold Itatic font and light blue
            // (0x9999ff) as the background color
            c.addTitle("Business Results 2001 vs 2002", "Times New Roman Bold Italic", 14
                       ).setBackground(0x9999ff);

            // Set the plotarea at (60, 45) and of size 500 x 210 pixels, using white (0xffffff) as
            // the background
            c.setPlotArea(60, 45, 500, 210, 0xffffff);

            // Swap the x and y axes to create a horizontal bar chart
            c.swapXY();

            // Add a title to the y axis using 11 pt Times Bold Italic as font
            c.yAxis().setTitle("Revenue (millions)", "Times New Roman Bold Italic", 11);

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

            // Disable x-axis ticks by setting the tick length to 0
            c.xAxis().setTickLength(0);

            // Add a stacked bar layer to the chart
            BarLayer layer = c.addBarLayer2(Chart.Stack);

            // Add the first two data sets to the chart as a stacked bar group
            layer.addDataGroup("2001");
            layer.addDataSet(data0, 0xaaaaff, "Local");
            layer.addDataSet(data1, 0x6666ff, "International");

            // Add the remaining data sets to the chart as another stacked bar group
            layer.addDataGroup("2002");
            layer.addDataSet(data2, 0xffaaaa, "Local");
            layer.addDataSet(data3, 0xff6666, "International");

            // Set the sub-bar gap to 0, so there is no gap between stacked bars with a group
            layer.setBarGap(0.2, 0);

            // Set the bar border to transparent
            layer.setBorderColor(Chart.Transparent);

            // Set the aggregate label format
            layer.setAggregateLabelFormat("Year {dataGroupName}\n{value} millions");

            // Set the aggregate label font to 8 point Arial Bold Italic
            layer.setAggregateLabelStyle("Arial Bold Italic", 8);

            // Reverse 20% space at the right during auto-scaling to allow space for the aggregate
            // bar labels
            c.yAxis().setAutoScale(0.2);

            // Add a legend box at (310, 300) using TopCenter alignment, with 2 column grid layout,
            // and use 8pt Arial Bold Italic as font
            LegendBox legendBox = c.addLegend2(310, 300, 2, "Arial Bold Italic", 8);

            legendBox.setAlignment(Chart.TopCenter);

            // Set the format of the text displayed in the legend box
            legendBox.setText("Year {dataGroupName} {dataSetName} Revenue");

            // Set the background and border of the legend box to transparent
            legendBox.setBackground(Chart.Transparent, Chart.Transparent);

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Year {dataGroupName} {dataSetName} {xLabel} Revenue: {value} millions'");
        }
Beispiel #11
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WPFChartViewer viewer, int chartIndex)
        {
            // The data for the 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");
        }
Beispiel #12
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WPFChartViewer viewer, int chartIndex)
        {
            // The data for the bar chart
            double[] data0 = { 100, 115, 165, 107, 67 };
            double[] data1 = { 85, 106, 129, 161, 123 };
            double[] data2 = { 67, 87, 86, 167, 157 };

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

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

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

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

            // Add a legend box at (480, 20) using vertical layout and 12pt Arial font. Set
            // background and border to transparent and key icon border to the same as the fill
            // color.
            LegendBox b = c.addLegend(480, 20, true, "Arial", 12);

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

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

            // Add a stacked bar layer
            BarLayer layer = c.addBarLayer2(Chart.Stack);

            // Add the three data sets to the bar layer
            layer.addDataSet(data0, 0xaaccee, "Server # 1");
            layer.addDataSet(data1, 0xbbdd88, "Server # 2");
            layer.addDataSet(data2, 0xeeaa66, "Server # 3");

            // Set the bar border to transparent
            layer.setBorderColor(Chart.Transparent);

            // Enable labelling for the entire bar and use 12pt Arial font
            layer.setAggregateLabelStyle("Arial", 12);

            // Enable labelling for the bar segments and use 12pt Arial font with center alignment
            layer.setDataLabelStyle("Arial", 10).setAlignment(Chart.Center);

            // For a vertical stacked bar with positive data, the first data set is at the bottom.
            // For the legend box, by default, the first entry at the top. We can reverse the legend
            // order to make the legend box consistent with the stacked bar.
            layer.setLegendOrder(Chart.ReverseLegend);

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

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

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

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} on {xLabel}: {value} MBytes/hour'");
        }