Exemplo n.º 1
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            // get chart data
            string           path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string           conn = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\ComponentOne Samples\Common\C1NWind.mdb;", path);
            string           sql  = "select * from products";
            OleDbDataAdapter da   = new OleDbDataAdapter(sql, conn);
            DataTable        dt   = new DataTable();

            da.Fill(dt);

            // sort and filter data
            DataView data = dt.DefaultView;

            data.Sort      = "UnitPrice";
            data.RowFilter = "CategoryID = 1";             // beverages

            // configure chart
            _c1c.Reset();
            _c1c.Font      = new Font("Tahoma", 8);
            _c1c.BackColor = Color.White;
            _c1c.ChartGroups[0].ChartType = Chart2DTypeEnum.Pie;

            // get series collection (pies have one series per slice)
            ChartDataSeriesCollection
                dscoll = _c1c.ChartGroups[0].ChartData.SeriesList;

            dscoll.Clear();

            // populate the series
            for (int i = 0; i < data.Count; i++)
            {
                ChartDataSeries series = dscoll.AddNewSeries();
                series.PointData.Length = 1;
                series.Y[0]             = data[i]["UnitPrice"];
                series.Label            = string.Format("{0} ({1:c})",
                                                        data[i]["ProductName"], data[i]["UnitPrice"]);
            }

            // show pie legend
            _c1c.Legend.Visible = true;
            _c1c.Legend.Text    = "Product Unit Prices";
        }
        private void ChartSetup()
        {
            // Reset the chart, position it, and appropriately anchor
            c1Chart1.Reset();
            c1Chart1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left;                  //!!VBPassThru

            // Setup the Chart appearance
            Style sty = c1Chart1.Style;

            sty.BackColor = Color.FromKnownColor(KnownColor.Window);

            // The Chart border
            Border b = sty.Border;

            b.BorderStyle  = BorderStyleEnum.Solid;
            b.Rounding.All = 10;
            b.Thickness    = 3;
            b.Color        = Color.Black;

            // Turn on tooltips
            c1Chart1.ToolTip.Enabled = true;

            // Generate scatter data and populate the chart.
            PointF [] scatter = GenerateScatterData(100, 100f, 75f);

            // Plot the data in the first ChartGroup.  For scatter data, turn off the lines.
            ChartDataSeries cds = c1Chart1.ChartGroups[0].ChartData.SeriesList.AddNewSeries();

            cds.LineStyle.Pattern = LinePatternEnum.None;
            cds.PointData.CopyDataIn(scatter);
            cds.TooltipText = "({#XVAL:0.00},{#YVAL:0.00})";

            // Force the chart to scale the axes right now.
            c1Chart1.GetImage();

            // Automatically label each of the points by its PointIndex.
            cds.DataLabel.Compass   = LabelCompassEnum.Auto;
            cds.DataLabel.Offset    = 4;
            cds.DataLabel.Connected = true;
            cds.DataLabel.Text      = "{#IPOINT}";
            cds.DataLabel.Visible   = true;

            // Provide Header for description
            Title t = c1Chart1.Header;

            t.Style.Font = new Font("Tahoma", 14);
            t.Text       = "Histogram/Frequency Data Measuring Distance from Crosshairs to Scatter data.";

            // Provide Footer for instructions
            t = c1Chart1.Footer;
            Font f = new Font("Tahoma", 12);

            t.AppendRtfText("Drag the ", f);
            t.AppendRtfText("Red", Color.Red, f);
            t.AppendRtfText(" arrows to move the crosshairs", Color.Black, f, HorizontalAlignment.Center);

            // Switch over the axes to mixed label mode and add some centered
            // markers to form a target.
            Area   carea   = c1Chart1.ChartArea;
            double xMarker = AddChartAxisMarker(carea.AxisX);
            double yMarker = AddChartAxisMarker(carea.AxisY);

            // Set the Axis Titles.
            carea.AxisX.Text  = "Scatter data X values / Distances from crosshair";
            carea.AxisY.Text  = "Scatter data Y values";
            carea.AxisY2.Text = "Count of data at distance from crosshair";
        }