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; }
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;"; // 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 DataBindTable method with the name of the Column to be used as the XValue Chart1.DataBindTable(myReader, "Name"); // close the reader and the connection myReader.Close(); myConnection.Close(); }
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; } }