//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}'");
        }
Пример #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Data for the chart as 2 random data series
            RanSeries r = new RanSeries(127);

            double[]   data0      = r.getSeries(180, 10, -1.5, 1.5);
            double[]   data1      = r.getSeries(180, 150, -15, 15);
            DateTime[] timeStamps = r.getDateSeries(180, new DateTime(2011, 1, 1), 86400);

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

            // Add a title to the chart using 18pt Times New Roman Bold Italic font
            c.addTitle("Plasma Stabilizer Energy Usage", "Times New Roman Bold Italic", 18);

            // Set the plotarea at (50, 55) with width 100 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(50, 55, c.getWidth() - 100, c.getHeight() - 90, c.linearGradientColor(0, 55, 0,
                                                                                                c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // Add a legend box at (50, 25) using horizontal layout. Use 10pt Arial Bold as font. Set the
            // background and border color to Transparent.
            c.addLegend(50, 25, false, "Arial Bold", 10).setBackground(Chart.Transparent);

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

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

            // Configure x-axis label format
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "{value|mm/yyyy} ", Chart.StartOfMonthFilter(
                                         ), "{value|mm}");

            // Add axis title using 10pt Arial Bold Italic font
            c.yAxis().setTitle("Power Usage (Watt)", "Arial Bold Italic", 10);
            c.yAxis2().setTitle("Effective Load (kg)", "Arial Bold Italic", 10);

            // Add a line layer to the chart using a line width of 2 pixels.
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);

            // Add 2 data series to the line layer
            layer.setXData(timeStamps);
            layer.addDataSet(data0, 0xcc0000, "Power Usage");
            layer.addDataSet(data1, 0x008800, "Effective Load").setUseYAxis2();

            // Assign the chart to the WPFChartViewer
            WPFChartViewer1.Chart = c;
        }
Пример #3
0
        private void FrmTrackLabel_Load(object sender, EventArgs e)
        {
            // Data for the chart as 3 random data series
            RanSeries r = new RanSeries(127);

            double[]   data0      = r.getSeries(100, 100, -15, 15);
            double[]   data1      = r.getSeries(100, 150, -15, 15);
            double[]   data2      = r.getSeries(100, 200, -15, 15);
            DateTime[] timeStamps = r.getDateSeries(100, new DateTime(2011, 1, 1), 86400);

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

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

            // Set the plotarea at (50, 55) with width 70 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(50, 55, c.getWidth() - 70, c.getHeight() - 90, c.linearGradientColor(0, 55, 0,
                                                                                               c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);

            // Add a legend box at (50, 25) using horizontal layout. Use 10pt Arial Bold as font. Set the
            // background and border color to Transparent.
            c.addLegend(50, 25, false, "Arial Bold", 10).setBackground(Chart.Transparent);

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

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

            // Configure x-axis label format
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "{value|mm/yyyy} ", Chart.StartOfMonthFilter(
                                         ), "{value|mm}");

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

            // Add a line layer to the chart using a line width of 2 pixels.
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);

            // Add 3 data series to the line layer
            layer.setXData(timeStamps);
            layer.addDataSet(data0, 0xff3333, "Alpha");
            layer.addDataSet(data1, 0x008800, "Beta");
            layer.addDataSet(data2, 0x3333cc, "Gamma");

            // Assign the chart to the WinChartViewer
            winChartViewer1.Chart = c;
        }
Пример #4
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // Data for the chart as 3 random data series
            RanSeries r = new RanSeries(127);

            double[]   data0      = r.getSeries(100, 100, -15, 15);
            double[]   data1      = r.getSeries(100, 150, -15, 15);
            double[]   data2      = r.getSeries(100, 200, -15, 15);
            DateTime[] timeStamps = r.getDateSeries(100, new DateTime(2011, 1, 1), 86400);

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

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

            // Set the plotarea at (50, 55) with width 70 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(50, 55, c.getWidth() - 70, c.getHeight() - 90, c.linearGradientColor(0, 55, 0,
                                                                                               c.getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff);


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

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

            // Configure x-axis label format
            c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "{value|mm/yyyy} ",
                                     Chart.StartOfMonthFilter(), "{value|mm}");

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

            // Add a line layer to the chart using a line width of 2 pixels.
            LineLayer layer = c.addLineLayer2();

            layer.setLineWidth(2);

            // Add 3 data series to the line layer
            layer.setXData(timeStamps);
            layer.addDataSet(data0, 0xff3333, "Alpha");
            layer.addDataSet(data1, 0x008800, "Beta");
            layer.addDataSet(data2, 0x3333cc, "Gamma");

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

            // Output Javascript chart model to the browser to suppport tracking cursor
            viewer.ChartModel = c.getJsChartModel();
        }
        //
        // Draw the thumbnail chart in the WebViewPortControl
        //
        private void drawFullChart(RazorViewPortControl vp, RazorChartViewer viewer)
        {
            //
            // For simplicity, in this demo, the data arrays are filled with hard coded data. In a real
            // application, you may use a database or other data source to load up the arrays. As this is
            // a small thumbnail chart, complete data may not be needed. For exmaple, if there are a
            // million points, a random sample may already be sufficient for the thumbnail chart.
            //
            double[] dataX0 = { 10, 15, 6, -12, 14, -8, 13, -3, 16, 12, 10.5, -7, 3, -10, -5, 2, 5 };
            double[] dataY0 = { 130, 150, 80, 110, -110, -105, -130, -15, -170, 125, 125, 60, 25, 150,
                                150,  15, 120 };
            double[] dataX1 = { 6, 7, -4, 3.5, 7, 8, -9, -10, -12, 11, 8, -3, -2, 8, 4, -15, 15 };
            double[] dataY1 = { 65, -40, -40, 45, -70, -80, 80, 10, -100, 105, 60, 50, 20, 170, -25, 50,
                                75 };
            double[] dataX2 = { -10, -12, 11, 8, 6, 12, -4, 3.5, 7, 8, -9, 3, -13, 16, -7.5, -10, -15 };
            double[] dataY2 = { 65,  -80, -40, 45, -70, -80, 80, 90, -100, 105, 60, -75, -150, -40, 120,
                                -50, -30 };

            // Create an XYChart object 120 x 120 pixels in size
            XYChart c = new XYChart(120, 120);

            // Set the plotarea to cover the entire chart and with no grid lines. Set 4 quadrant
            // coloring, where the colors alternate between lighter and deeper grey (d8d8d8/eeeeee).
            c.setPlotArea(0, 0, c.getWidth() - 1, c.getHeight() - 1, -1, -1, -1, Chart.Transparent
                          ).set4QBgColor(0xd8d8d8, 0xeeeeee, 0xd8d8d8, 0xeeeeee, 0x000000);

            // Set 4 quadrant mode, with both x and y axes symetrical around the origin
            c.setAxisAtOrigin(Chart.XYAxisAtOrigin, Chart.XAxisSymmetric + Chart.YAxisSymmetric);

            // The x and y axis scales reflect the full range of the view port
            c.xAxis().setLinearScale(viewer.getValueAtViewPort("x", 0), viewer.getValueAtViewPort("x", 1
                                                                                                  ), Chart.NoValue);
            c.yAxis().setLinearScale(viewer.getValueAtViewPort("y", 0), viewer.getValueAtViewPort("y", 1
                                                                                                  ), Chart.NoValue);

            // Add scatter layer, using 5 pixels red (ff33333) X shape symbols
            c.addScatterLayer(dataX0, dataY0, "Group A", Chart.Cross2Shape(), 5, 0xff3333);

            // Add scatter layer, using 5 pixels green (33ff33) circle symbols
            c.addScatterLayer(dataX1, dataY1, "Group B", Chart.CircleShape, 5, 0x33ff33);

            // Add scatter layer, using 5 pixels blue (3333ff) triangle symbols
            c.addScatterLayer(dataX2, dataY2, "Group C", Chart.TriangleSymbol, 5, 0x3333ff);

            // Output the chart
            vp.Image = c.makeWebImage(Chart.PNG);
        }
Пример #6
0
        private void drawFullChart(WPFViewPortControl vpc, WPFChartViewer viewer)
        {
            // Create an XYChart object of size 640 x 60 pixels
            XYChart c = new XYChart(640, 60);

            // Set the plotarea with the same horizontal position as that in the main chart for alignment.
            c.setPlotArea(55, 0, c.getWidth() - 80, c.getHeight() - 1, 0xc0d8ff, -1, 0x888888,
                          Chart.Transparent, 0xffffff);

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

            // Put the x-axis labels inside the plot area by setting a negative label gap. Use
            // setLabelAlignment to put the label at the right side of the tick.
            c.xAxis().setLabelGap(-1);
            c.xAxis().setLabelAlignment(1);

            // Set the y axis stem and labels to transparent (that is, hide the labels)
            c.yAxis().setColors(Chart.Transparent, Chart.Transparent);

            // Add a line layer for the lines with fast line mode enabled
            LineLayer layer = c.addLineLayer();

            layer.setFastLineMode();

            // Now we add the 3 data series to a line layer, using the color red (0xff3333), green
            // (0x008800) and blue (0x3333cc)
            layer.setXData(timeStamps);
            layer.addDataSet(dataSeriesA, 0xff3333);
            layer.addDataSet(dataSeriesB, 0x008800);
            layer.addDataSet(dataSeriesC, 0x3333cc);

            // The x axis scales should reflect the full range of the view port
            c.xAxis().setDateScale(viewer.getValueAtViewPort("x", 0), viewer.getValueAtViewPort("x", 1));

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

            // For the auto-scaled y-axis, as we hide the labels, we can disable axis rounding. This can
            // make the axis scale fit the data tighter.
            c.yAxis().setRounding(false, false);

            // Output the chart
            vpc.Chart = c;
        }
Пример #7
0
        public override void Draw()
        {
            // Move the grid lines in front of the contour layer
            //chart.getPlotArea().moveGridBefore(layer);

            // Add a color axis (the legend) in which the top center is anchored at
            // (245, 455). Set the length to 330 pixels and the labels on the top
            // side.
            int w = chart.getWidth();
            int h = chart.getHeight();

//            ColorAxis cAxis = layer.setColorAxis(w-3*margin, 0, Chart.TopLeft2, w/2,
//                Chart.Left);
//            cAxis.setBoxMargin(2);
//            cAxis.setBoundingBox(Chart.Transparent);
//            // Set the color axis range as 0 to 20, with a step every 2 units
//            //cAxis.setTickDensity(1,-1);
//            cAxis.setLinearScale(min, max, Math.Abs(max - min) / 10);
//            cAxis.setColorGradient();

            chart.layout();
            chart.layoutAxes();
            viewer.Chart = chart;
        }
Пример #8
0
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, string img)
        {
            // The data for the line chart
            double[] data0  = { 42, 49, 33, 38, 64, 56, 29, 41, 44, 57, 59, 42 };
            double[] data1  = { 65, 75, 47, 34, 42, 49, 73, 62, 90, 69, 66, 78 };
            double[] data2  = { 36, 28, 25, 28, 38, 20, 22, 30, 25, 33, 30, 24 };
            string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
                                "Aug", "Sep", "Oct", "Nov", "Dec" };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Revenue of {dataSetName} in {xLabel}: US$ {value}M'");
        }
Пример #9
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'");
        }
Пример #10
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // The data for the chart
            double[]   dataY = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1 };
            DateTime[] dataX = { new DateTime(2008,                                                 7, 1,  0,  0,  0), new DateTime(2008,                 7, 1,  2, 17, 2
                                                                                                                                    ), new DateTime(2008, 7,  1,  8,   5,               30), new DateTime(2008, 7,  1, 10,  54, 10),
                                 new DateTime(2008,                                                 7, 1, 15, 40,  0), new DateTime(2008,                 7, 1, 18, 22, 20),
                                 new DateTime(2008,                                                 7, 1, 22, 17, 14), new DateTime(2008,                 7, 2,  2, 55, 50),
                                 new DateTime(2008,                                                 7, 2,  8, 17, 14), new DateTime(2008,                 7, 2, 11, 55, 50),
                                 new DateTime(2008,                                                 7, 2, 13, 17, 14), new DateTime(2008,                 7, 2, 17, 55, 50),
                                 new DateTime(2008,                                                 7, 2, 20, 17, 14), new DateTime(2008,                 7, 3,  0,  0, 0) };

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

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

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

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

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

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

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

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

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

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

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

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

            layer0.setXData(dataX);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            layer0.setLineWidth(2);

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

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

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

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

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

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

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

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} at hour {xLabel} = {value}'");
        }
Пример #13
0
        //
        // Draw the track box with legend
        //
        private void trackBoxLegend(XYChart c, int mouseX, int mouseY)
        {
            // Clear the current dynamic layer and get the DrawArea object to draw on it.
            DrawArea d = c.initDynamicLayer();

            // The plot area object
            PlotArea plotArea = c.getPlotArea();

            // Get the data x-value that is nearest to the mouse
            double xValue = c.getNearestXValue(mouseX);

            // Compute the position of the box. This example assumes a label based x-axis, in which the
            // labeling spacing is one x-axis unit. So the left and right sides of the box is 0.5 unit from
            // the central x-value.
            int boxLeft   = c.getXCoor(xValue - 0.5);
            int boxRight  = c.getXCoor(xValue + 0.5);
            int boxTop    = plotArea.getTopY();
            int boxBottom = plotArea.getBottomY();

            // Draw the track box
            d.rect(boxLeft, boxTop, boxRight, boxBottom, 0x000000, Chart.Transparent);

            // Container to hold the legend entries
            ArrayList legendEntries = new ArrayList();

            // Iterate through all layers to build the legend array
            for (int i = 0; i < c.getLayerCount(); ++i)
            {
                Layer layer = c.getLayerByZ(i);

                // The data array index of the x-value
                int xIndex = layer.getXIndexOf(xValue);

                // Iterate through all the data sets in the layer
                for (int j = 0; j < layer.getDataSetCount(); ++j)
                {
                    ChartDirector.DataSet dataSet = layer.getDataSetByZ(j);

                    // Build the legend entry, consist of the legend icon, the name and the data value.
                    double dataValue = dataSet.getValue(xIndex);
                    if ((dataValue != Chart.NoValue) && (dataSet.getDataColor() != Chart.Transparent))
                    {
                        legendEntries.Add(dataSet.getLegendIcon() + " " + dataSet.getDataName() + ": " +
                                          c.formatValue(dataValue, "{value|P4}"));
                    }
                }
            }

            // Create the legend by joining the legend entries
            if (legendEntries.Count > 0)
            {
                legendEntries.Reverse();
                string legend = "<*block,bgColor=FFFFCC,edgeColor=000000,margin=5*><*font,underline=1*>" +
                                c.xAxis().getFormattedLabel(xValue) + "<*/font*><*br*>" + String.Join("<*br*>", (string[])
                                                                                                      legendEntries.ToArray(typeof(string))) + "<*/*>";

                // Display the legend at the bottom-right side of the mouse cursor, and make sure the legend
                // will not go outside the chart image.
                TTFText t = d.text(legend, "Arial Bold", 8);
                t.draw(Math.Min(mouseX + 12, c.getWidth() - t.getWidth()), Math.Min(mouseY + 18, c.getHeight()
                                                                                    - t.getHeight()), 0x000000, Chart.TopLeft);
            }
        }
Пример #14
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;
        }
Пример #15
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   = { 800, 600, 1000, 1400 };
            double[] widths = { 250, 500, 960, 460 };
            string[] labels = { "Wind", "Hydro", "Coal", "Natural Gas" };

            // The colors to use
            int[] colors = { 0x00aa00, 0x66aaee, 0xee6622, 0xffbb00 };

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

            // Add a title to the chart using 15pt Arial Italic font
            c.addTitle("Energy Generation Breakdown", "Arial Italic", 15);

            // Set the plotarea at (60, 60) and of (chart_width - 90) x (chart_height - 100) in
            // size. Use a vertical gradient color from light blue (f9f9ff) to sky blue (aaccff) as
            // background. Set grid lines to white (ffffff).
            int plotAreaBgColor = c.linearGradientColor(0, 60, 0, c.getHeight() - 40, 0xaaccff,
                                                        0xf9fcff);

            c.setPlotArea(60, 60, c.getWidth() - 90, c.getHeight() - 100, plotAreaBgColor, -1, -1,
                          0xffffff);

            // Add a legend box at (50, 30) using horizontal layout and transparent background.
            c.addLegend(55, 30, false).setBackground(Chart.Transparent);

            // Add titles to x/y axes with 10 points Arial Bold font
            c.xAxis().setTitle("Mega Watts", "Arial Bold", 10);
            c.yAxis().setTitle("Cost per MWh (dollars)", "Arial Bold", 10);

            // Set the x axis rounding to false, so that the x-axis will fit the data exactly
            c.xAxis().setRounding(false, false);

            // In ChartDirector, there is no bar layer that can have variable bar widths, but you
            // may create a bar using an area layer. (A bar can be considered as the area under a
            // rectangular outline.) So by using a loop to create one bar per area layer, we can
            // achieve a variable width bar chart.

            // starting position of current bar
            double currentX = 0;

            for (int i = 0; i < data.Length; ++i)
            {
                // ending position of current bar
                double nextX = currentX + widths[i];

                // outline of the bar
                double[] dataX = { currentX, currentX, nextX, nextX };
                double[] dataY = { 0, data[i], data[i], 0 };

                // create the area layer to fill the bar
                AreaLayer layer = c.addAreaLayer(dataY, colors[i], labels[i]);
                layer.setXData(dataX);

                // Tool tip for the layer
                layer.setHTMLImageMap("", "", "title='" + labels[i] + ": " + widths[i] + " MW at $"
                                      + data[i] + " per MWh'");

                // the ending position becomes the starting position of the next bar
                currentX = nextX;
            }

            // Output the chart
            viewer.Chart = c;

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable");
        }
        //
        // 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();
        }
Пример #17
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("", "", "");
            }
        }
Пример #18
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WPFChartViewer viewer, int chartIndex)
        {
            // The data for the line chart
            double[] data0  = { 410, 420, 500, 590 };
            double[] data1  = { 500, 370, 680, 850 };
            string[] labels = { "Q1", "Q2", "Q3", "Q4" };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='Revenue in {xLabel} {dataSetName}: US$ {value}M'");
        }
Пример #19
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}'");
        }
        //
        // 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));

            // 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 (!viewer.IsInMouseMoveEvent)
            {
                trackLineLabel(c, (null == viewer.Chart) ? c.getPlotArea().getRightX() :
                               viewer.PlotAreaMouseX);
            }

            viewer.Chart = c;
        }
        //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, 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();

            // 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.Chart = c;

            //include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("clickable", "",
                                                "title='{dataSetName} revenue on {xLabel}: US${value}K ({percent}%)'");
        }
Пример #22
0
        public void createChart(WinChartViewer viewer, double[] data, string img)
        {
            // The data for the chart
            Chart.setLicenseCode("DEVP-2LSU-B4LX-YCTY-2DF2-77EE");
            //double[] data = {16, 15, 9.7, 5.2, 3};

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

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

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

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

            c.setBorder(10);

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

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

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

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

            //LineLayer lineLayer = c.addLineLayer2();

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

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

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

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

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

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


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

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

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

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

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

            // Output the chart
            viewer.Chart = c;
        }
Пример #23
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 of size 640 x 400 pixels
            XYChart c = new XYChart(640, 400);

            // 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 15pt Arial Bold font
            c.addTitle("   Zooming and Scrolling with Viewport Control", "Arial Bold", 15);

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

            // 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 10pt Arial Bold 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);

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

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

            //
            // 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<*br*>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;
        }
Пример #24
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(512, 288);

            // 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("Gerçek Zamanlı Motor Verileri", "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("Angular Rate", "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, "Motor Devir");
            layer.addDataSet(viewPortDataSeriesB, 0x0000ff, "Motor Sicaklik");

            //================================================================================
            // 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;
        }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // The data for the bar chart
            double[] data = { 1350, 1600, 1950, 2300, 2700 };

            // The labels for the bar chart
            string[] labels = { "2001", "2002", "2003", "2004", "2005" };

            // The colors for the bars
            int[] colors = { 0xcc0000, 0x66aaee, 0xeebb22, 0xcccccc, 0xcc88ff };

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

            // Use the white on black palette, which means the default text and line colors are white
            c.setColors(Chart.whiteOnBlackPalette);

            // Use a vertical gradient color from blue (0000cc) to deep blue (000044) as background. Use
            // rounded corners of 30 pixels radius for the top-left and bottom-right corners.
            c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight(), 0x0000cc, 0x000044));
            c.setRoundedFrame(0xffffff, 30, 0, 30, 0);

            // Add a title using 18pt Times New Roman Bold Italic font. Add 6 pixels top and bottom
            // margins to the title.
            ChartDirector.TextBox title = c.addTitle("Annual Revenue for Star Tech",
                                                     "Times New Roman Bold Italic", 18);
            title.setMargin2(0, 0, 6, 6);

            // Add a separator line in white color just under the title
            c.addLine(20, title.getHeight(), c.getWidth() - 21, title.getHeight(), 0xffffff);

            // Tentatively set the plotarea at (70, 80) and of 480 x 240 pixels in size. Use transparent
            // border and white grid lines
            c.setPlotArea(70, 80, 480, 240, -1, -1, Chart.Transparent, 0xffffff);

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

            // Add a multi-color bar chart layer using the supplied data. Use bar gradient lighting with
            // the light intensity from 0.75 to 2.0
            c.addBarLayer3(data, colors).setBorderColor(Chart.Transparent, Chart.barLighting(0.75, 2.0));

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

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

            // Set the bottom y-axis title using 10pt Arial Bold font
            c.yAxis().setTitle("USD (millions)", "Arial Bold", 10);

            // Set y-axes to transparent
            c.yAxis().setColors(Chart.Transparent);
            c.yAxis2().setColors(Chart.Transparent);

            // Disable ticks on the x-axis by setting the tick color to transparent
            c.xAxis().setTickColor(Chart.Transparent);

            // Set the label styles of all axes to 8pt Arial Bold font
            c.xAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis().setLabelStyle("Arial Bold", 8);
            c.yAxis2().setLabelStyle("Arial Bold", 8);

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

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

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

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

            //                  };

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

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

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

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

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

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

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

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

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


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

            // Add a spline layer to the chart

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

            c.setNumberFormat(',');

            SplineLayer layer = c.addSplineLayer();

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

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

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

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

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

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

            // Output the chart
            viewer.Chart = c;

            //include tool tip for the chart
            //viewer.ImageMap = c.getHTMLImageMap("clickable", "",
            //    "title='{dataSetName} at t = {xLabel} hour: {value} KJ/liter'");
        }
Пример #27
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // The data for the chart
            double[] data = { 40, 15, 7, 5, 2 };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("");
        }
Пример #28
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");
        }
Пример #29
0
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // In this example, the data points are unevenly spaced on the x-axis
            double[]   dataY = { 4.7, 4.7, 6.6, 2.2, 4.7, 4.0, 4.0, 5.1, 4.5, 4.5, 6.8, 4.5, 4, 2.1, 3, 2.5,
                                 2.5, 3.1 };
            DateTime[] dataX = { new DateTime(1999,                                                                   7,  1), new DateTime(2000,                 1,  1), new DateTime(2000,                 2,
                                                                                                                                                                                      1), new DateTime(2000,   4,                1), new DateTime(2000,   5,                8), new DateTime(2000,  7, 5),
                                 new DateTime(2001,                                                                   3,  5), new DateTime(2001,                 4,  7), new DateTime(2001,                 5, 9),
                                 new DateTime(2002,                                                                   2,  4), new DateTime(2002,                 4,  4), new DateTime(2002,                 5, 8),
                                 new DateTime(2002,                                                                   7,  7), new DateTime(2002,                 8, 30), new DateTime(2003,                 1, 2),
                                 new DateTime(2003,                                                                   2, 16), new DateTime(2003,                11,  6), new DateTime(2004,                 1, 4) };

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

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

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

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

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

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

            legendBox.setAlignment(Chart.BottomCenter);

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Include tool tip for the chart
            viewer.ImageMap = c.getHTMLImageMap("", "", "title='{x|mmm dd, yyyy}: {value}%'");
        }
Пример #30
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;
        }