Пример #1
0
        /// <summary>
        /// Initializes chart data from XML.
        /// </summary>
        protected void InitializeXMLData()
        {
            //Initializes a new DataSet.
            DataSet xmlDataSet = new DataSet();

            //Loads the dataset with xml data.
            xmlDataSet.ReadXmlSchema(WinFormsUtils.FindFile(@"..\..\..\..\..\..\Common\Data\Chart", "dataschema.xslt"));
            xmlDataSet.ReadXml(WinFormsUtils.FindFile(@"..\..\..\..\..\..\Common\Data\Chart", "data.xml"));

            //Initializes new chart series.
            ChartSeries series = new ChartSeries();

            series.Name = tableName;

            model        = new ChartDataBindModel(xmlDataSet, "Products");
            model.XName  = "ExpiresDate";
            model.YNames = new string[] { "Quantity" };

            series.SeriesModel = model;

            //Adds the series to the ChartSeriesCollection.
            this.chartControl1.Series.Add(series);

            //Specifies the value type of the Chart Axis.
            this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.DateTime;

            //Specifies the format in which the Date-Time values display.
            this.chartControl1.PrimaryXAxis.DateTimeFormat = "MM/dd/yy";

            //Specifies the mode of displaying the label of the x-axis on intersection.
            this.chartControl1.PrimaryXAxis.LabelIntersectAction = ChartLabelIntersectAction.MultipleRows;

            //Specifies the column width mode for the Column Type chart.
            this.chartControl1.ColumnWidthMode = ChartColumnWidthMode.FixedWidthMode;
        }
Пример #2
0
        /// <summary>
        /// Initializes chart data from Excel Sheet.
        /// </summary>
        protected void InitializeChartExcelData()
        {
            string fileName = WinFormsUtils.FindFile(@"..\..\..\..\..\..\Common\Data\Chart", "ChartData.xls");

            //The Oledbconnection.
            OleDbConnection excelConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;\"");

            excelConn.Open();

            //Query for retriving the data from the excel sheet.
            string query = "Select * From [Sheet1$A1:B11]";

            OleDbCommand excelCommand = new OleDbCommand(query, excelConn);

            OleDbDataReader excelReader = excelCommand.ExecuteReader(CommandBehavior.CloseConnection);

            //Load the contents to a dataset.
            DataSet excelDataSet = ConvertToDataSet(excelReader, "ExcelTable");



            this.chartControl1.Indexed = true;

            //Initializes new chart series.
            ChartSeries series = new ChartSeries();

            series.Name  = tableName;
            series.Type  = ChartSeriesType.Column;
            model        = new ChartDataBindModel(excelDataSet, "ExcelTable");
            model.XName  = "X Value";
            model.YNames = new string[] { "Y Value" };

            series.SeriesModel = model;

            //Specifies the column width mode for the Column Type chart.
            this.chartControl1.ColumnWidthMode = ChartColumnWidthMode.FixedWidthMode;

            //Adds the series to the ChartSeriesCollection.
            this.chartControl1.Series.Add(series);

            //Close the connection.
            excelReader.Close();
            excelConn.Close();
            this.chartControl1.Text = "Chart Data From Excel";
        }
Пример #3
0
        /// <summary>
        /// Imports chart data from a CSV file.
        /// </summary>
        protected void InitializeChartFromCSV()
        {
            string fileName = WinFormsUtils.FindFile(@"..\..\..\..\..\..\Common\Data\Chart\", "ChartData.csv");

            OleDbConnection csvConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + ";Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"");

            csvConn.Open();

            //Query for retriving the data from the csv file.
            string query = "Select * From " + fileName;

            OleDbCommand csvCommand = new OleDbCommand(query, csvConn);

            OleDbDataReader csvReader = csvCommand.ExecuteReader(CommandBehavior.CloseConnection);

            //Load the contents to a dataset.
            DataSet csvDataSet = ConvertToDataSet(csvReader, "CSVTable");



            this.chartControl1.Indexed = true;

            //Initializes new chart series.
            ChartSeries series = new ChartSeries();

            series.Style.DisplayText     = true;
            series.Style.TextOrientation = ChartTextOrientation.Up;
            series.Name = tableName;

            model        = new ChartDataBindModel(csvDataSet, "CSVTable");
            model.XName  = "X Value";
            model.YNames = new string[] { "Y Value" };

            series.SeriesModel = model;

            //Adds the series to the ChartSeriesCollection.
            this.chartControl1.Series.Add(series);

            ////Specifies the column width mode for the Column Type chart.
            this.chartControl1.ColumnWidthMode = ChartColumnWidthMode.FixedWidthMode;

            //Close the connection.
            csvReader.Close();
            csvConn.Close();
        }
Пример #4
0
        /// <summary>
        /// Initializes chart data from access database.
        /// </summary>
        protected void InitializeChartData()
        {
            // The Access database
            string fileName           = WinFormsUtils.FindFile(@"..\..\..\..\..\..\Common\Data\Chart", "ChartData.mdb");
            string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName;

            // Define the database query
            string mySelectQuery = "SELECT City, ID, Population FROM Demographics";

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

            myCommand.Connection.Open();

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

            //Load the contents into a dataset.
            DataSet dataSet = ConvertToDataSet(myReader, "Demographics");



            //Initializes new chart series.
            ChartSeries series = new ChartSeries();

            series.Style.DisplayText     = true;
            series.Style.TextOrientation = ChartTextOrientation.Up;
            series.Name = "Products";

            ChartDataBindModel model = new ChartDataBindModel(dataSet, "Demographics");

            model.XName  = "ID";
            model.YNames = new string[] { "Population" };

            series.SeriesModel = model;

            this.xAxisLabelModel           = new ChartDataBindAxisLabelModel(dataSet, "Demographics");
            this.xAxisLabelModel.LabelName = "City";


            //Adds the series to the ChartSeriesCollection.
            this.chartControl1.Series.Add(series);

            this.xAxisLabelModel.PositionIndex = 1;
            this.chartControl1.PrimaryXAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.UserMode;

            //this.chartControl1.PrimaryXAxis.AutoValueType = false;
            this.chartControl1.PrimaryXAxis.LabelsImpl = this.xAxisLabelModel;

            this.chartControl1.PrimaryXAxis.CustomLabelsParameter = ChartCustomLabelsParameter.Position;

            //Specifies the mode of displaying the label of the x-axis on intersection.
            this.chartControl1.PrimaryXAxis.LabelIntersectAction = ChartLabelIntersectAction.MultipleRows;

            //Specifies the column width mode for the Column Type chart.
            // this.chartControl1.ColumnWidthMode = ChartColumnWidthMode.RelativeWidthMode;

            // Close the reader and the connection
            myReader.Close();
            myConnection.Close();
            //Turns off the legend.
            this.chartControl1.Legend.Visible = false;

            this.chartControl1.Text = "Highest populated cities in the world";

            // this.chartControl1.Series3D = true;
            this.chartControl1.Spacing = 20;
        }