private void ArrayBinding_Load(object sender, System.EventArgs e)
        {
            // resolve the address to the Access database
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string fileNameString = mainForm.applicationPath + "\\data\\chartdata.mdb";

            // initialize a connection string
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

            // define the database query
            string mySelectQuery = "SELECT * FROM REPS;";

            // create a database connection object using the connection string
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);

            // create a database command on the connection using query
            OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

            myConnection.Open();

            // set chart data source - the data source must implement IEnumerable
            Chart1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // set series members names for the X and Y values
            Chart1.Series["Series 1"].XValueMember  = "Name";
            Chart1.Series["Series 1"].YValueMembers = "Sales";

            // data bind to the selected data source
            Chart1.DataBind();

            myCommand.Dispose();
            myConnection.Close();
        }
예제 #2
0
        private void ArrayBinding_Load(object sender, System.EventArgs e)
        {
            // Access database
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;

            // The XML document
            string fileNameString = mainForm.applicationPath + "\\data\\data.xml";
            string fileNameSchema = mainForm.applicationPath + "\\data\\data.xsd";

            // Initializes a new instance of the DataSet class
            DataSet custDS = new DataSet();

            // Reads an XML schema into the DataSet.
            custDS.ReadXmlSchema(fileNameSchema);

            // Reads XML schema and data into the DataSet.
            custDS.ReadXml(fileNameString);

            // Initializes a new instance of the DataView class
            DataView firstView = new DataView(custDS.Tables[0]);

            Chart1.Series.Clear();
            // Since the DataView implements and IEnumerable, pass the reader directly into
            // the DataBindTable method with the name of the column used for the X value.
            Chart1.DataBindTable(firstView, "Name");

            // Set series appearance
            Chart1.Series[0].ChartType   = SeriesChartType.Bar;
            Chart1.Series[0].Font        = new Font("Trebuchet MS", 8);
            Chart1.Series[0].Color       = System.Drawing.Color.FromArgb(220, 224, 64, 10);
            Chart1.Series[0].BorderWidth = 0;
        }
예제 #3
0
        private void ArrayBinding_Load(object sender, System.EventArgs e)
        {
            // Access database
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string fileNameString = mainForm.applicationPath + "\\data\\chartdata.mdb";

            // initialize a connection string
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

            // define the database query
            string mySelectQuery = "SELECT * FROM REPS;";

            // create a database connection object using the connection string
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);

            // create a database command on the connection using query
            OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

            // open the connection
            myCommand.Connection.Open();

            // Initializes a new instance of the OleDbDataAdapter class
            OleDbDataAdapter custDA = new OleDbDataAdapter();

            custDA.SelectCommand = myCommand;

            // Initializes a new instance of the DataSet class
            DataSet custDS = new DataSet();

            // Adds rows in the DataSet
            custDA.Fill(custDS, "Customers");

            // Initializes a new instance of the DataView class
            DataView firstView = new DataView(custDS.Tables[0]);

            // since the DataView implements and IEnumerable, pass the reader directly into
            // the DataBind method with the name of the Columns selected in the query
            Chart1.Series["Default"].Points.DataBindXY(firstView, "Name", firstView, "Sales");

            // Closes the connection to the data source. This is the preferred
            // method of closing any open connection.
            myCommand.Connection.Close();
        }
        private void Chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            // Painting series object
            if (e.ChartElement is System.Windows.Forms.DataVisualization.Charting.Series)
            {
                // Add custom painting only to the series with name "Sereis2"
                Series series = (Series)e.ChartElement;
                if (series.Name == "Series2")
                {
                    // Find data point with maximum Y value
                    DataPoint dataPoint = series.Points.FindMaxByValue();

                    // Image path
                    System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
                    string fileNameString = mainForm.applicationPath + "\\Images\\money.png";

                    // Load bitmap from file
                    System.Drawing.Image bitmap = Bitmap.FromFile(fileNameString);

                    // Set Red color as transparent
                    ImageAttributes attrib = new ImageAttributes();
                    attrib.SetColorKey(Color.Red, Color.Red, ColorAdjustType.Default);

                    // Calculates marker position depending on the data point X and Y values
                    RectangleF imagePosition = RectangleF.Empty;
                    imagePosition.X = (float)e.ChartGraphics.GetPositionFromAxis(
                        "Default", AxisName.X, dataPoint.XValue);
                    imagePosition.Y = (float)e.ChartGraphics.GetPositionFromAxis(
                        "Default", AxisName.Y, dataPoint.YValues[0]);
                    imagePosition        = e.ChartGraphics.GetAbsoluteRectangle(imagePosition);
                    imagePosition.Width  = bitmap.Width;
                    imagePosition.Height = bitmap.Height;
                    imagePosition.Y     -= bitmap.Height;
                    imagePosition.X     -= bitmap.Width / 2;

                    // Draw image
                    e.ChartGraphics.Graphics.DrawImage(bitmap,
                                                       Rectangle.Round(imagePosition),
                                                       0, 0, bitmap.Width, bitmap.Height,
                                                       GraphicsUnit.Pixel,
                                                       attrib);

                    // Dispose image object
                    bitmap.Dispose();
                }
            }
        }
예제 #5
0
        private void BindData()
        {
            string file = "DataFile.csv";

            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string path = mainForm.applicationPath + "\\data\\";

            if (System.IO.File.Exists(path + file))
            {
                // Create a select statement and a connection string.
                string mySelectQuery = "Select * from " + file;
                string ConStr        = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                                       path + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\"";

                OleDbConnection myConnection = new OleDbConnection(ConStr);

                // create a database command on the connection using query
                OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

                // open the connection
                myCommand.Connection.Open();

                // create a database reader
                OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

                // column 1 is a time value, column 2 is a double
                // databind the reader to the chart using the DataBindXY method
                Chart1.Series[0].Points.DataBindXY(myReader, "1", myReader, "2");

                // Close connection and data reader
                myReader.Close();
                myConnection.Close();
            }
        }
예제 #6
0
        private void ArrayBinding_Load(object sender, System.EventArgs e)
        {
            // Access database
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;

            // Set Excel data file name
            string fileNameString = mainForm.applicationPath + "\\data\\ExcelData.xls";

            // Create connection object by using the preceding connection string.
            string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                           fileNameString + ";Extended Properties=\"Excel 8.0;HDR=YES\"";
            OleDbConnection myConnection = new OleDbConnection(sConn);

            myConnection.Open();

            // The code to follow uses a SQL SELECT command to display the data from the worksheet.
            // Create new OleDbCommand to return data from worksheet.
            OleDbCommand myCommand = new OleDbCommand("Select * From [data1$A1:E25]", myConnection);

            // create a database reader
            OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // Populate the chart with data from the Excel file.
            Chart1.DataBindTable(myReader, "HOUR");

            // close the reader and the connection
            myReader.Close();
            myConnection.Close();

            // Set series appearance
            foreach (Series ser in Chart1.Series)
            {
                ser.ShadowOffset = 1;
                ser.BorderWidth  = 2;
                ser.ChartType    = SeriesChartType.Line;
            }
        }
        private string GetImage(string fileName)
        {
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string imageFileName = mainForm.applicationPath + "\\";

            imageFileName += "Images\\";
            imageFileName += fileName;

            return(imageFileName);
        }
예제 #8
0
        private void ChartAppearanceChange()
        {
            // Enable/disable appearance controls
            ForeColorCom.Enabled  = (HatchStyle.SelectedIndex != 0 || Gradient.SelectedIndex != 0);
            BorderColor.Enabled   = (BorderDashStyle.SelectedIndex != 0);
            BorderSizeCom.Enabled = (BorderDashStyle.SelectedIndex != 0);

            // Set Back Color
            Chart1.BackColor = Color.FromName(BackColorCom.GetItemText(BackColorCom.SelectedItem));

            // Set Back Gradient End Color
            Chart1.BackSecondaryColor = Color.FromName(ForeColorCom.GetItemText(ForeColorCom.SelectedItem));

            // Set Gradient Type
            if (Gradient.SelectedItem != null)
            {
                Chart1.BackGradientStyle = (GradientStyle)GradientStyle.Parse(typeof(GradientStyle), Gradient.GetItemText(Gradient.SelectedItem));
            }

            // Set Gradient Type
            if (HatchStyle.SelectedItem != null)
            {
                Chart1.BackHatchStyle = (ChartHatchStyle)ChartHatchStyle.Parse(typeof(ChartHatchStyle), HatchStyle.GetItemText(HatchStyle.SelectedItem));
            }

            // Set background image
            if (!ShowImageCheck.Checked)
            {
                Chart1.BackImage   = "";
                ImageAlign.Enabled = false;
                ImageMode.Enabled  = false;
            }
            else
            {
                ImageMode.Enabled  = true;
                ImageAlign.Enabled = (ImageMode.SelectedIndex == 5);

                // Set chart image
                System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
                string imageFileName = mainForm.CurrentSamplePath;
                imageFileName   += "\\Flag.gif";
                Chart1.BackImage = imageFileName;
                Chart1.BackImageTransparentColor = Color.Red;

                // Set Image Mode
                if (ImageMode.SelectedItem != null)
                {
                    Chart1.BackImageWrapMode = (ChartImageWrapMode)ChartImageWrapMode.Parse(typeof(ChartImageWrapMode), ImageMode.SelectedItem.ToString());
                }

                // Set Image Alignment
                if (ImageAlign.SelectedItem != null)
                {
                    Chart1.BackImageAlignment = (ChartImageAlignmentStyle)ChartImageAlignmentStyle.Parse(typeof(ChartImageAlignmentStyle), ImageAlign.SelectedItem.ToString());
                }
            }

            // Set Border Width
            if (BorderSizeCom.SelectedItem != null)
            {
                Chart1.BorderWidth = int.Parse(BorderSizeCom.GetItemText(BorderSizeCom.SelectedItem));
            }

            // Set Border Style
            if (BorderDashStyle.SelectedItem != null)
            {
                Chart1.BorderDashStyle = (ChartDashStyle)ChartDashStyle.Parse(typeof(ChartDashStyle), BorderDashStyle.GetItemText(BorderDashStyle.SelectedItem));
            }

            // Set Border Color
            Chart1.BorderColor = Color.FromName(BorderColor.GetItemText(BorderColor.SelectedItem));
        }
예제 #9
0
        private void TemplateSampleControl_Load(object sender, System.EventArgs e)
        {
            // Generate rundom data
            GenerateRandomData(chart1.Series["Input"]);

            // Set chart types for output data
            chart1.Series["Input"].ChartType = SeriesChartType.Line;

            // Set current selection
            comboBoxPeriod.SelectedIndex = 0;

            // Set all cells image transp color to red
            for (int i = 1; i < 5; i++)
            {
                chart1.Legends["Default"].CustomItems[i].Cells[0].ImageTransparentColor = Color.Red;
            }

            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;

            // Set image for all custom items
            chart1.Legends["Default"].CustomItems[1].Cells[0].Image = mainForm.CurrentSamplePath + @"\chk_checked.png";
            chart1.Legends["Default"].CustomItems[2].Cells[0].Image = mainForm.CurrentSamplePath + @"\chk_checked.png";
            chart1.Legends["Default"].CustomItems[3].Cells[0].Image = mainForm.CurrentSamplePath + @"\chk_checked.png";
            chart1.Legends["Default"].CustomItems[4].Cells[0].Image = mainForm.CurrentSamplePath + @"\chk_checked.png";

            // Set tag property for all custom items to appropriate series
            chart1.Legends["Default"].CustomItems[1].Tag = chart1.Series["Simple"];
            chart1.Legends["Default"].CustomItems[2].Tag = chart1.Series["Exponential"];
            chart1.Legends["Default"].CustomItems[3].Tag = chart1.Series["Triangular"];
            chart1.Legends["Default"].CustomItems[4].Tag = chart1.Series["Weighted"];
        }
        private void SetMarkers()
        {
            // Get image path
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string imagePath = mainForm.CurrentSamplePath;

            imagePath += "\\";

            // Randomly set dividend and split markers
            Random random = new Random();

            for (int index = 0; index < 2; index++)
            {
                int pointIndex = random.Next(0, chart1.Series["Price"].Points.Count);

                chart1.Series["Price"].Points[pointIndex].MarkerImage = imagePath + "DividentLegend.bmp";
                chart1.Series["Price"].Points[pointIndex].MarkerImageTransparentColor = Color.White;
                chart1.Series["Price"].Points[pointIndex].ToolTip = "#VALX{D}\n0.15 - dividend per share";

                pointIndex = random.Next(0, chart1.Series["Price"].Points.Count);

                chart1.Series["Price"].Points[pointIndex].MarkerImage = imagePath + "SplitLegend.bmp";

                chart1.Series["Price"].Points[pointIndex].MarkerImageTransparentColor = Color.White;
                chart1.Series["Price"].Points[pointIndex].ToolTip = "#VALX{D}\n2 for 1 split";
            }
        }
        private void FinancialChartType_Load(object sender, System.EventArgs e)
        {
            // Get image path
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string imagePath = mainForm.CurrentSamplePath;

            imagePath += "\\";

            // Add custom legend items
            LegendItem legendItem = new LegendItem();

            legendItem.Name       = "Dividend";
            legendItem.ImageStyle = LegendImageStyle.Marker;
            legendItem.MarkerImageTransparentColor = Color.White;
            legendItem.MarkerImage = imagePath + "DividentLegend.bmp";
            chart1.Legends[0].CustomItems.Add(legendItem);

            legendItem            = new LegendItem();
            legendItem.Name       = "Split";
            legendItem.ImageStyle = LegendImageStyle.Marker;
            legendItem.MarkerImageTransparentColor = Color.White;
            legendItem.MarkerImage = imagePath + "SplitLegend.bmp";
            chart1.Legends[0].CustomItems.Add(legendItem);

            // Populate series data
            FillData();

            SetMarkers();

            // Save default appearance
            chart1.Serializer.Save(defaultViewStyleStream);

            comboBoxChartType.SelectedIndex = 0;
            comboBoxMarks.SelectedIndex     = 0;
        }
예제 #12
0
        private void UpdateChartSettings()
        {
            // Get app path
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;

            string imageFileName = mainForm.CurrentSamplePath;

            imageFileName += "\\";

            // Prepare data base connection and query strings
            imageFileName += "..\\..\\..\\data\\chartdata.mdb";
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + imageFileName;
            string mySelectQuery      = "SELECT * FROM STOCKDATA WHERE SymbolName = 'ABC' ORDER BY Date";

            // Open data base connection
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);
            OleDbCommand    myCommand    = new OleDbCommand(mySelectQuery, myConnection);

            myCommand.Connection.Open();

            // Fill data set object
            OleDbDataAdapter custDA = new OleDbDataAdapter();

            custDA.SelectCommand = myCommand;
            DataSet custDS = new DataSet();

            custDA.Fill(custDS, "Customers");
            myCommand.Connection.Close();

            // Initializes a new instance of the DataView class
            DataView dataView = new DataView(custDS.Tables[0]);

            // Data bind to the reader
            chart1.Series["High"].Points.DataBindXY(dataView, "Date", dataView, "High");
            chart1.Series["Low"].Points.DataBindXY(dataView, "Date", dataView, "Low");
            chart1.Series["Open"].Points.DataBindXY(dataView, "Date", dataView, "Open");
            chart1.Series["Close"].Points.DataBindXY(dataView, "Date", dataView, "Close");

            // Remove all data points before 10/1/2001
            DateTime date = new DateTime(2001, 10, 1, 0, 0, 0);

            chart1.DataManipulator.Filter(CompareMethod.LessThan, date.ToOADate(), "High", "High", "X");
            chart1.DataManipulator.Filter(CompareMethod.LessThan, date.ToOADate(), "Low", "Low", "X");
            chart1.DataManipulator.Filter(CompareMethod.LessThan, date.ToOADate(), "Open", "Open", "X");
            chart1.DataManipulator.Filter(CompareMethod.LessThan, date.ToOADate(), "Close", "Close", "X");

            // Group data by week
            chart1.DataManipulator.Group("AVE", 1, IntervalType.Weeks, "High");
            chart1.DataManipulator.Group("AVE", 1, IntervalType.Weeks, "Low");
            chart1.DataManipulator.Group("AVE", 1, IntervalType.Weeks, "Open");
            chart1.DataManipulator.Group("AVE", 1, IntervalType.Weeks, "Close");

            // Show data as stock chart
            if (checkBoxShowAsStockChart.Checked)
            {
                // Hide series
                chart1.Series["High"].ChartArea  = "";
                chart1.Series["Low"].ChartArea   = "";
                chart1.Series["Open"].ChartArea  = "";
                chart1.Series["Close"].ChartArea = "";

                // Merge data from 4 different series in to one with 4 Y values
                chart1.DataManipulator.CopySeriesValues("High:Y,Low:Y,Open:Y,Close:Y", "Stock:Y1,Stock:Y2,Stock:Y3,Stock:Y4");

                // Set stock series attributes
                chart1.Series["Stock"].ChartType    = SeriesChartType.Stock;
                chart1.Series["Stock"].BorderWidth  = 1;
                chart1.Series["Stock"].ShadowOffset = 1;
                //chart1.Series["Stock"].Color = Color.Green;
            }
            else
            {
                // Delet "Stock" series
                if (chart1.Series.Count > 4)
                {
                    chart1.Series["Stock"].ChartArea = "";
                    chart1.Series.RemoveAt(4);
                }

                // Show series
                chart1.Series["High"].ChartArea  = "Default";
                chart1.Series["Low"].ChartArea   = "Default";
                chart1.Series["Open"].ChartArea  = "Default";
                chart1.Series["Close"].ChartArea = "Default";
            }
        }
예제 #13
0
        private void PopulateData()
        {
            // Prepare data base connection and query strings
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string fileNameString = mainForm.applicationPath + "\\";

            fileNameString += "data\\chartdata.mdb";
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;
            string mySelectQuery      = "SELECT * FROM STOCKDATA WHERE SymbolName = '" + comboBoxStockSymbol.Text + "' ORDER BY Date";

            // Open data base connection
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);
            OleDbCommand    myCommand    = new OleDbCommand(mySelectQuery, myConnection);

            myCommand.Connection.Open();

            // Create a database reader
            OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // Data bind to the reader
            chart1.Series["StockPrice"].Points.Clear();
            chart1.Series["StockPrice"].Points.DataBindXY(myReader, "Date", myReader, "High,Low,Open,Close");

            // Group series data points by interval. Different formulas are used for each Y value:
            //   Y1 (High) - maximum of all Y1 points values in the group
            //   Y2 (Low) - minimum of all Y2 points values in the group
            //   Y3 (Open) - Y3 value of the first point in the group
            //   Y4 (Close) - Y4 value of the last point in the group
            chart1.Series["GroupedStockPrice"].Points.Clear();
            if (comboBoxGroupingInterval.Text == "Week")
            {
                chart1.DataManipulator.Group("Y1:MAX,Y2:MIN,Y3:FIRST,Y4:LAST", 1, IntervalType.Weeks, "StockPrice", "GroupedStockPrice");
            }
            else if (comboBoxGroupingInterval.Text == "Month")
            {
                chart1.DataManipulator.Group("Y1:MAX,Y2:MIN,Y3:FIRST,Y4:LAST", 1, IntervalType.Months, "StockPrice", "GroupedStockPrice");
            }
            else if (comboBoxGroupingInterval.Text == "Quarter")
            {
                chart1.DataManipulator.Group("Y1:MAX,Y2:MIN,Y3:FIRST,Y4:LAST", 3, IntervalType.Months, "StockPrice", "GroupedStockPrice");
            }

            // close the reader and the connection
            myReader.Close();
            myConnection.Close();

            chart1.ResetAutoValues();
            chart1.Invalidate();
        }
예제 #14
0
        private void DataBind()
        {
            // Remove all series
            chart1.Series.Clear();

            // Access database
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string fileNameString = mainForm.applicationPath + "\\data\\chartdata.mdb";

            // initialize a connection string
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;


            // define the database query
            string mySelectQuery = "SELECT * FROM SALESCOUNTS;";

            // create a database connection object using the connection string
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);

            // create a database command on the connection using query
            OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

            // open the connection
            myCommand.Connection.Open();

            // Initializes a new instance of the OleDbDataAdapter class
            OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();

            myDataAdapter.SelectCommand = myCommand;

            // Initializes a new instance of the DataSet class
            DataSet myDataSet = new DataSet();

            // Adds rows in the DataSet
            myDataAdapter.Fill(myDataSet, "Query");


            foreach (DataRow row in myDataSet.Tables["Query"].Rows)
            {
                // for each Row, add a new series
                string seriesName = row["SalesRep"].ToString();
                chart1.Series.Add(seriesName);
                chart1.Series[seriesName].ChartType    = SeriesChartType.Line;
                chart1.Series[seriesName].BorderWidth  = 2;
                chart1.Series[seriesName].ShadowOffset = 2;


                for (int colIndex = 1; colIndex < myDataSet.Tables["Query"].Columns.Count; colIndex++)
                {
                    // for each column (column 1 and onward), add the value as a point
                    string columnName = myDataSet.Tables["Query"].Columns[colIndex].ColumnName;
                    int    YVal       = (int)row[columnName];

                    chart1.Series[seriesName].Points.AddXY(columnName, YVal);
                }
            }


            this.dataGrid1.SetDataBinding(myDataSet, "Query");

            // Closes the connection to the data source. This is the preferred
            // method of closing any open connection.
            myCommand.Connection.Close();
        }
예제 #15
0
        private void UpdateChartSettings()
        {
            // Set bubble series shape to image
            if (comboBoxShape.Text == "Image")
            {
                // Get image path
                System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
                string imageFileName = mainForm.CurrentSamplePath;
                imageFileName += "\\Face.bmp";

                chart1.Series["Default"].MarkerImage = imageFileName;
                chart1.Series["Default"].MarkerImageTransparentColor = Color.White;
                chart1.Series["Default"].MarkerStyle = MarkerStyle.None;
            }

            // Set "bubble" series shape
            else
            {
                chart1.Series["Default"].MarkerImage = "";
                chart1.Series["Default"].MarkerStyle = (MarkerStyle)MarkerStyle.Parse(typeof(MarkerStyle), comboBoxShape.Text);
            }

            // Set max bubble size
            chart1.Series["Default"]["BubbleMaxSize"] = comboBoxMaxSize.Text;

            // Show Y value or bubble sise as point labels
            chart1.Series["Default"].IsValueShownAsLabel = true;
            if (checkBoxShowSizeInLabel.Checked)
            {
                chart1.Series["Default"]["BubbleUseSizeForLabel"] = "true";
            }
            else
            {
                chart1.Series["Default"]["BubbleUseSizeForLabel"] = "false";
            }

            // Set scale for the bubble size
            if (comboBoxMinScale.Text != "Auto")
            {
                chart1.Series["Default"]["BubbleScaleMin"] = comboBoxMinScale.Text;
            }
            else
            {
                chart1.Series["Default"].DeleteCustomProperty("BubbleScaleMin");
            }

            if (comboBoxMaxScale.Text != "Auto")
            {
                chart1.Series["Default"]["BubbleScaleMax"] = comboBoxMaxScale.Text;
            }
            else
            {
                chart1.Series["Default"].DeleteCustomProperty("BubbleScaleMax");
            }

            if (checkBoxShow3D.Checked)
            {
                chart1.ChartAreas["Default"].Area3DStyle.Enable3D = true;
            }
            else
            {
                chart1.ChartAreas["Default"].Area3DStyle.Enable3D = false;
            }
        }
예제 #16
0
        private void LegendCustomItems_Load(object sender, System.EventArgs e)
        {
            // Disable legend item for the first series
            Chart1.Series[0].IsVisibleInLegend = false;

            // Add simple custom legend item
            Chart1.Legends["Default"].CustomItems.Add(Color.FromArgb(32, 120, 147, 190), "Critical Values");

            // Add custom legend item with line style
            LegendItem legendItem = new LegendItem();

            legendItem.Name         = "Line Style Item";
            legendItem.ImageStyle   = LegendImageStyle.Line;
            legendItem.ShadowOffset = 1;
            legendItem.Color        = Color.LightBlue;
            legendItem.MarkerStyle  = MarkerStyle.Circle;
            Chart1.Legends["Default"].CustomItems.Add(legendItem);

            // Add custom legend item with marker style
            legendItem                   = new LegendItem();
            legendItem.Name              = "Marker Style Item";
            legendItem.ImageStyle        = LegendImageStyle.Marker;
            legendItem.ShadowOffset      = 1;
            legendItem.Color             = Color.Yellow;
            legendItem.MarkerStyle       = MarkerStyle.Cross;
            legendItem.MarkerSize        = 10;
            legendItem.MarkerBorderColor = Color.Black;
            Chart1.Legends["Default"].CustomItems.Add(legendItem);

            // Add custom legend item with image
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string imageFileName = mainForm.CurrentSamplePath;

            imageFileName += "\\Flag.gif";

            legendItem       = new LegendItem();
            legendItem.Name  = "Image Style Item";
            legendItem.Image = imageFileName;
            legendItem.BackImageTransparentColor = Color.White;
            Chart1.Legends["Default"].CustomItems.Add(legendItem);

            // Add a strip line
            StripLine stripLine = new StripLine();

            stripLine.BackColor      = Chart1.Legends["Default"].CustomItems[0].Color;
            stripLine.IntervalOffset = 500;
            stripLine.StripWidth     = 300;
            Chart1.ChartAreas["Default"].AxisY.StripLines.Add(stripLine);
        }
예제 #17
0
        private void ArrayBinding_Load(object sender, System.EventArgs e)
        {
            // Access database
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string fileNameString = mainForm.applicationPath + "\\data\\chartdata.mdb";

            // initialize a connection string
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

            // define the database query
            string mySelectQuery = "SELECT Name, Sales FROM REPS WHERE RegionID < 3;";

            // create a database connection object using the connection string
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);

            // create a database command on the connection using query
            OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

            // open the connection
            myCommand.Connection.Open();

            // create a database reader
            OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // since the reader implements and IEnumerable, pass the reader directly into
            // the DataBind method with the name of the Column selected in the query
            Chart1.Series["Default"].Points.DataBindXY(myReader, "Name", myReader, "Sales");

            // close the reader and the connection
            myReader.Close();
            myConnection.Close();
        }
예제 #18
0
        private void PopulateData()
        {
            // Prepare data base connection and query strings
            System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
            string fileNameString = mainForm.applicationPath + "\\";

            fileNameString += "data\\chartdata.mdb";
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;
            string mySelectQuery      = "SELECT * FROM DETAILEDSALES ORDER BY SaleDate";

            // Open data base connection
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);
            OleDbCommand    myCommand    = new OleDbCommand(mySelectQuery, myConnection);

            myCommand.Connection.Open();

            // Create a database reader
            OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // Data bind to the reader
            chart1.Series["Sales"].Points.Clear();
            chart1.Series["Sales"].Points.DataBindXY(myReader, "SaleDate", myReader, "Net");

            // close the reader and the connection
            myReader.Close();
            myConnection.Close();

            // Group series data points by interval. Different formulas are used for each Y value:
            string formula = comboBoxGroupingFormulaY.Text +
                             ", X:" + comboBoxGroupingFormulaX.Text;

            if (comboBoxGroupingInterval.Text == "Week")
            {
                chart1.DataManipulator.Group(formula, 1, IntervalType.Weeks, "Sales", "Grouped Sales");
            }
            else if (comboBoxGroupingInterval.Text == "2 Weeks")
            {
                chart1.DataManipulator.Group(formula, 2, IntervalType.Weeks, "Sales", "Grouped Sales");
            }
            else if (comboBoxGroupingInterval.Text == "Month")
            {
                chart1.DataManipulator.Group(formula, 1, IntervalType.Months, "Sales", "Grouped Sales");
            }

            chart1.Series["Grouped Sales"].ShadowOffset = 0;
            chart1.Series["Grouped Sales"].BorderWidth  = 1;

            // Change chart type and appearance attributes of the grouped series
            if (comboBoxGroupingFormulaY.Text == "HiLoOpCl")
            {
                chart1.Series["Grouped Sales"].ChartType    = SeriesChartType.Stock;
                chart1.Series["Grouped Sales"].Color        = Color.FromArgb(224, 64, 10);
                chart1.Series["Grouped Sales"].BorderWidth  = 2;
                chart1.Series["Grouped Sales"].ShadowOffset = 1;
            }
            else if (comboBoxGroupingFormulaY.Text == "HiLo")
            {
                chart1.Series["Grouped Sales"].ChartType = SeriesChartType.SplineRange;
                chart1.Series["Grouped Sales"].Color     = Color.FromArgb(128, 252, 180, 65);
            }
            else
            {
                chart1.Series["Grouped Sales"].ChartType = SeriesChartType.Column;
            }
        }
        private void DataBind()
        {
            try
            {
                // Remove all series
                Chart1.Series.Clear();

                // Access database
                System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
                string fileNameString = mainForm.applicationPath + "\\data\\chartdata.mdb";

                // initialize a connection string
                string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

                // define the database query
                string mySelectQuery = "SELECT * FROM REPSALES;";

                // create a database connection object using the connection string
                OleDbConnection myConnection = new OleDbConnection(myConnectionString);

                // create a database command on the connection using query
                OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

                // open the connection
                myCommand.Connection.Open();

                // Bind grid to the original data
                OleDbDataAdapter custDA = new OleDbDataAdapter();
                custDA.SelectCommand = myCommand;
                DataSet custDS = new DataSet();
                custDA.Fill(custDS, "Customers");
                this.dataGrid.SetDataBinding(custDS, "Customers");
                this.dataGrid.TableStyles[0].MappingName = "Customers";

                // create a database reader
                OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

                // data bind chart to a table where all rows are grouped by the "Name" column
                Chart1.DataBindCrossTable(
                    myReader,
                    (comboBoxGroupBy.SelectedIndex == 0) ? "Name" : "Year",
                    (comboBoxGroupBy.SelectedIndex == 0) ? "Year" : "Name",
                    "Sales",
                    "Label=Commissions{C0}");

                // close the reader and the connection
                myReader.Close();
                myConnection.Close();

                // Set series appearance
                MarkerStyle marker = MarkerStyle.Star4;
                foreach (Series ser in Chart1.Series)
                {
                    ser.ShadowOffset      = 1;
                    ser.BorderWidth       = 3;
                    ser.ChartType         = SeriesChartType.Line;
                    ser.MarkerSize        = 12;
                    ser.MarkerStyle       = marker;
                    ser.MarkerBorderColor = Color.FromArgb(64, 64, 64);
                    ser.Font = new Font("Trebuchet MS", 8, FontStyle.Bold);
                    marker++;
                }
            }
            catch (Exception)
            {
            }
        }
예제 #20
0
        private void comboBoxTemplate_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (comboBoxTemplate.Text == "None")
            {
                // Reset chart appearance
                chart1.Serializer.Content = SerializationContents.Appearance;
                chart1.Serializer.Reset();
            }
            else
            {
                // Get template path
                System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm;
                string imageFileName = mainForm.CurrentSamplePath;
                imageFileName += "\\" + comboBoxTemplate.Text + ".xml";

                // Load template
                chart1.Serializer.IsResetWhenLoading = false;
                chart1.LoadTemplate(imageFileName);
            }
        }