示例#1
0
        public Image CreateGraphFromWaterML(Series mySeries, int widthPixels, int heightPixels)
        {
            ZedGraph.GraphPane p = SetupGraphPane(mySeries, widthPixels, heightPixels);

            if (mySeries != null)
            {
                if (mySeries.DataValueList != null)
                {
                    DataSourcePointList source = new DataSourcePointList();
                    source.DataSource = mySeries.DataValueList;
                    source.XDataMember = "LocalDateTime";
                    source.YDataMember = "Value";

                    LineItem line = p.AddCurve(mySeries.Variable.Name, source, Color.Blue, SymbolType.None);

                    line.Line.Width = 2f;

                    p.XAxis.Type = AxisType.Date;

                    //adjust x axis range
                    p.XAxis.Scale.Min = XDate.DateTimeToXLDate(mySeries.BeginDateTime);
                    p.XAxis.Scale.Max = XDate.DateTimeToXLDate(mySeries.EndDateTime);

                    p.AxisChange();

                    //Bitmap bm = new Bitmap(10, 10);
                    //Graphics ge = Graphics.FromImage(bm);
                    //p.AxisChange(ge);
                }
            }

            Image img = p.GetImage();
            return img;
        }
 /// <summary> 
 /// Constructor to initialize the DataSourcePointList from an 
 /// existing <see cref="DataSourcePointList" /> 
 /// </summary> 
 public DataSourcePointList( DataSourcePointList rhs )
     : this()
 {
     _bindingSource.DataSource = rhs._bindingSource.DataSource;
     if ( rhs._xDataMember != null )
         _xDataMember = (string)rhs._xDataMember.Clone();
     if ( rhs._yDataMember != null )
         _yDataMember = (string)rhs._yDataMember.Clone();
     if ( rhs._zDataMember != null )
         _zDataMember = (string)rhs._zDataMember.Clone();
     if ( rhs._tagDataMember != null )
         _tagDataMember = (string)rhs._tagDataMember.Clone();
 }
示例#3
0
 /// <summary>
 /// Constructor to initialize the DataSourcePointList from an
 /// existing <see cref="DataSourcePointList" />
 /// </summary>
 public DataSourcePointList(DataSourcePointList rhs) : this()
 {
     _dataSource = rhs._dataSource;
     if (rhs._xDataMember != null)
     {
         _xDataMember = (string)rhs._xDataMember.Clone();
     }
     if (rhs._yDataMember != null)
     {
         _yDataMember = (string)rhs._yDataMember.Clone();
     }
     if (rhs._zDataMember != null)
     {
         _zDataMember = (string)rhs._zDataMember.Clone();
     }
     if (rhs._tagDataMember != null)
     {
         _tagDataMember = (string)rhs._tagDataMember.Clone();
     }
 }
 /// <summary>
 /// Constructor to initialize the DataSourcePointList from an
 /// existing <see cref="DataSourcePointList" />
 /// </summary>
 public DataSourcePointList(DataSourcePointList rhs)
     : this()
 {
     BindingSource.DataSource = rhs.BindingSource.DataSource;
     if (rhs.XDataMember != null)
     {
         XDataMember = (string)rhs.XDataMember.Clone();
     }
     if (rhs.YDataMember != null)
     {
         YDataMember = (string)rhs.YDataMember.Clone();
     }
     if (rhs.ZDataMember != null)
     {
         ZDataMember = (string)rhs.ZDataMember.Clone();
     }
     if (rhs.TagDataMember != null)
     {
         TagDataMember = (string)rhs.TagDataMember.Clone();
     }
 }
示例#5
0
        /// <summary>
        /// Pass params to build the chart on start up, set null (is default) for nothing display
        /// </summary>
        /// <param name="sensor"></param>
        /// <param name="group"></param>
        /// <param name="pictureView"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="chartName"></param>
        /// <param name="xLabel"></param>
        /// <param name="yLabel"></param>
        /// <param name="showCalcValue"></param>
        public ChartViewForm(Sensor sensor = null, Group group = null, PictureView pictureView = null, DateTime? startDate = null,
                             DateTime? endDate = null, string chartName = "Chart View", string xLabel = "Value", string yLabel = "Datetime", bool showCalcValue = true)
        {
            // set value to private field
            _sensor = sensor;
            _group = group;
            // ...
            // continue here
            InitializeComponent();
            GraphPane myPane;
            LineItem mycurve;
            Random randomGen = new Random();
            myPane = zedChartMain.GraphPane;
            myPane.XAxis.Type = AxisType.Date;
            myPane.XAxis.Scale.Format = "HH:mm:ss\ndd-MM-yyyy";
            myPane.Title.Text = chartName;
            myPane.XAxis.Title.Text = xLabel;
            myPane.YAxis.Title.Text = yLabel;
            myPane.XAxis.MajorGrid.IsVisible = true;
            myPane.YAxis.MajorGrid.IsVisible = true;

            if (sensor != null)
            {
                List<SensorValue> listvalue = entityConntext.SensorValues.Where(ent => ent.SensorID == sensor.SensorID).ToList();
                DataSourcePointList dsp = new DataSourcePointList();
                dsp.DataSource = listvalue;
                if (!showCalcValue)
                {
                    dsp.YDataMember = "RawValue";
                }
                if (showCalcValue)
                {
                    dsp.YDataMember = "CalcValue";
                }
                dsp.XDataMember = "MeaTime";

                mycurve = myPane.AddCurve(sensor.Name, dsp, Color.FromArgb(randomGen.Next(255), randomGen.Next(255), randomGen.Next(255)));
                mycurve.Line.Width = 1;
            }

            if (group != null)
            {
                List<Sensor> sensorsInGroup = group.Sensors.ToList();
                for (int i = 0; i < sensorsInGroup.Count; i++)
                {
                    int idsen = Convert.ToInt16(sensorsInGroup[i].SensorID);
                    List<SensorValue> listvalue = entityConntext.SensorValues.Where(ent => ent.SensorID == idsen).ToList();

                    DataSourcePointList dsp = new DataSourcePointList();
                    dsp.DataSource = listvalue;
                    if (!showCalcValue)
                    {
                        dsp.YDataMember = "RawValue";
                    }
                    if (showCalcValue)
                    {
                        dsp.YDataMember = "CalcValue";
                    }
                    dsp.XDataMember = "MeaTime";

                    mycurve = myPane.AddCurve(sensorsInGroup[i].Name, dsp, Color.FromArgb(randomGen.Next(255), randomGen.Next(255), randomGen.Next(255)));
                    mycurve.Line.Width = 1;

                }
            }

            //lenh hien thi chart
            zedChartMain.IsShowPointValues = true;
            zedChartMain.AxisChange();
            zedChartMain.Invalidate();
            zedChartMain.Refresh();
        }
示例#6
0
文件: Form1.cs 项目: Jungwon/ZedGraph
        private void CreateGraph_DataSourcePointListTestDual( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;
            myPane.Title.Text = "DataSourcePointList Test";
            myPane.XAxis.Title.Text = "Item";
            myPane.YAxis.Title.Text = "Quantity or Value";

            DataTable productsTable = new DataTable();
            productsTable.Columns.Add( "Item", typeof( double ) );
            productsTable.Columns.Add( "Quantity", typeof( double ) );
            productsTable.Columns.Add( "Value", typeof( double ) );
            productsTable.Rows.Add( 1, 10.0, 20.0 );
            productsTable.Rows.Add( 2, 20.0, 23.0 );
            productsTable.Rows.Add( 3, 50.0, 25.0 );
            productsTable.Rows.Add( 4, 40.0, 33.0 );
            productsTable.Rows.Add( 5, 10.0, 31.0 );
            productsTable.Rows.Add( 6, 70.0, 38.0 );
            productsTable.Rows.Add( 7, 30.0, 42.0 );
            productsTable.Rows.Add( 8, 20.0, 44.0 );
            productsTable.Rows.Add( 9, 40.0, 50.0 );

            DataSourcePointList dspl = new DataSourcePointList();
            dspl.DataSource = productsTable;
            dspl.XDataMember = "Item";
            dspl.YDataMember = "Quantity";
            LineItem myCurve = myPane.AddCurve( "Quantity", dspl, Color.Blue );

            DataSourcePointList dspl2 = new DataSourcePointList();
            dspl2.DataSource = productsTable;
            dspl2.XDataMember = "Item";
            dspl2.YDataMember = "Value";
            LineItem myCurve2 = myPane.AddCurve( "Value", dspl2, Color.Red );

            z1.AxisChange();
        }
示例#7
0
文件: Form1.cs 项目: Jungwon/ZedGraph
        private void CreateGraph_DataSourcePointListTest( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;
            myPane.Title.Text = "DataSourcePointList Test";
            myPane.XAxis.Title.Text = "Item";
            myPane.YAxis.Title.Text = "Quantity";

            DataSourcePointList dspl = new DataSourcePointList();
            DataTable productsTable = new DataTable();
            productsTable.Columns.Add( "Item", typeof( double ) );
            productsTable.Columns.Add( "Quantity", typeof( double ) );
            productsTable.Rows.Add( 1, 10.0 );
            productsTable.Rows.Add( 2, 20.0 );
            productsTable.Rows.Add( 3, 50.0 );
            productsTable.Rows.Add( 4, 40.0 );
            productsTable.Rows.Add( 5, 10.0 );
            productsTable.Rows.Add( 6, 70.0 );
            productsTable.Rows.Add( 7, 30.0 );
            productsTable.Rows.Add( 8, 20.0 );
            productsTable.Rows.Add( 9, 40.0 );

            //Dim ProductsTable As DataTable = GetProductsData()

            DataRow dr = productsTable.Rows[0];
            //DataRowView drv = productsTable.Rows[2] as DataRowView;
            //System.Reflection.PropertyInfo pInfo = dr.GetType().GetProperty( "Item" );

            //System.Reflection.PropertyInfo pInfo = dr[0].GetType();

            double x1 = (double) dr["Item"];

            double x = (double) dr[0];
            double y = (double) dr[1];

            dspl.DataSource = productsTable;
            dspl.XDataMember = "Item";
            dspl.YDataMember = "Quantity";
            dspl.ZDataMember = null;
            //dspl.TagDataMember = "Item";

            myPane.XAxis.Type = AxisType.Text;
            LineItem myCurve = myPane.AddCurve( "Item", dspl, Color.Blue );
            myCurve.Line.IsVisible = false;
            z1.IsShowPointValues = true;
            z1.AxisChange();
        }
示例#8
0
文件: Form1.cs 项目: Jungwon/ZedGraph
        private void CreateGraph_DataSourcePointListQuery( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;
            myPane.Title.Text = "DataSourcePointList Test";
            myPane.XAxis.Title.Text = "Item";
            myPane.YAxis.Title.Text = "Quantity";

            DataSourcePointList dspl = new DataSourcePointList();

            //string connStr = @"server=tonydev;database=northwind;uid=tony;pwd=hrmmm";
            //string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\testdb.mdb;Mode=Read";
            //string connStr = @"server=(local)\SQLExpress;AttachDbFileName=c:\temp\testdb.mdb;" +
            //	"Integrated Security=true;User Instance=true";
            //string connStr = @"Data Source=.\SQLExpress;" + //User ID=sa;Password=;" +
            //	@"AttachDbFileName=C:\SQL Server 2000 Sample Databases\Northwind.mdf;" +
            //	@"Initial Catalog=northwind; User Instance=true";
            //@"Integrated Security=true;User Instance=true";

            //string connStr = @"server=.\\SQLExpress;uid=testuser;pwd=testuser;database=Northwind;";
            string connStr = @"Driver=Microsoft.Jet.OLEDB.4.0;" +
                @"Data Source=e:\My Documents\db1.mdb";

            SqlConnection connection = new SqlConnection( connStr );
            connection.Open();

            //string strConn = "Provider=SQLOLEDB;Data Source=(local)\\NetSDK;" +
            //		"Initial Catalog=Northwind;Trusted_Connection=Yes;";
            //string strSQL = "SELECT CustomerID, CompanyName, ContactName, Phone " +
            //		"FROM Customers";
            //OleDbDataAdapter da = new OleDbDataAdapter( strSQL, strConn );
            //DataSet ds = new DataSet();
            //da.Fill( ds, "Customers" );

            //			string cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Northwind.mdb;Persist Security Info=False";
            //			string sql = "SELECT * FROM Orders";
            //			OleDbConnection con = new OleDbConnection( cn );
            //			OleDbDataAdapter adapt = new OleDbDataAdapter();
            //			adapt.SelectCommand = new OleDbCommand( sql, con );

            DataTable productsTable = new DataTable();
            productsTable.Columns.Add( "Item", typeof( double ) );
            productsTable.Columns.Add( "Quantity", typeof( double ) );
            productsTable.Rows.Add( 1, 10.0 );
            productsTable.Rows.Add( 2, 20.0 );
            productsTable.Rows.Add( 3, 50.0 );
            productsTable.Rows.Add( 4, 40.0 );
            productsTable.Rows.Add( 5, 10.0 );
            productsTable.Rows.Add( 6, 70.0 );
            productsTable.Rows.Add( 7, 30.0 );
            productsTable.Rows.Add( 8, 20.0 );
            productsTable.Rows.Add( 9, 40.0 );

            //Dim ProductsTable As DataTable = GetProductsData()

            DataRow dr = productsTable.Rows[0];
            //DataRowView drv = productsTable.Rows[2] as DataRowView;
            //System.Reflection.PropertyInfo pInfo = dr.GetType().GetProperty( "Item" );

            //System.Reflection.PropertyInfo pInfo = dr[0].GetType();

            double x1 = (double) dr["Item"];

            double x = (double) dr[0];
            double y = (double) dr[1];

            dspl.DataSource = productsTable;
            dspl.XDataMember = "Item";
            dspl.YDataMember = "Quantity";
            dspl.ZDataMember = null;
            //dspl.TagDataMember = "Item";

            myPane.XAxis.Type = AxisType.Text;
            LineItem myCurve = myPane.AddCurve( "Item", dspl, Color.Blue );
            myCurve.Line.IsVisible = false;
            z1.IsShowPointValues = true;
            z1.AxisChange();
        }
示例#9
0
文件: Form1.cs 项目: Jungwon/ZedGraph
        //CreateGraph_DataSourcePointListTest( zedGraphControl1 );
        private void CreateGraph_DataSourcePointListArrayList( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;
            myPane.Title.Text = "DataSourcePointList Test";
            myPane.XAxis.Title.Text = "Item";
            myPane.YAxis.Title.Text = "Quantity";

            DataSourcePointList dspl = new DataSourcePointList();
            List<MySimplePoint> list = new List<MySimplePoint>();
            list.Add( new MySimplePoint( 1, 10.0, "Point #1" ) );
            list.Add( new MySimplePoint( 2, 20.0, "Point #2" ) );
            list.Add( new MySimplePoint( 3, 50.0, "Point #3" ) );
            list.Add( new MySimplePoint( 4, 40.0, "Point #4" ) );
            list.Add( new MySimplePoint( 5, 10.0, "Point #5" ) );
            list.Add( new MySimplePoint( 6, 70.0, "Point #6" ) );
            list.Add( new MySimplePoint( 7, 30.0, "Point #7" ) );
            list.Add( new MySimplePoint( 8, 20.0, "Point #8" ) );
            list.Add( new MySimplePoint( 9, 40.0, "Point #9" ) );

            dspl.DataSource = list;
            dspl.XDataMember = "X";
            dspl.YDataMember = "Y";
            dspl.ZDataMember = null;
            dspl.TagDataMember = "Tag";

            //System.Reflection.PropertyInfo pInfo = dr.GetType().GetProperty( "ItemX" );

            //System.Reflection.PropertyInfo pInfo = dr[0].GetType();

            //double x1 = (double)dr["Itemx"];

            //double x = (double)dr[0];
            //double y = (double)dr[1];

            myPane.XAxis.Type = AxisType.Text;
            LineItem myCurve = myPane.AddCurve( "Item", dspl, Color.Blue );
            myCurve.Line.IsVisible = false;
            z1.IsShowPointValues = true;
            z1.AxisChange();
        }
示例#10
0
文件: Form1.cs 项目: Jungwon/ZedGraph
        /*
                    myPane.Title.Text = "DataSourcePointList Test";
                    myPane.XAxis.Title.Text = "Date";
                    myPane.YAxis.Title.Text = "Freight Charges ($US)";

                    // Create a new DataSourcePointList to handle the database connection
                    DataSourcePointList dspl = new DataSourcePointList();
                    // Create a TableAdapter instance to access the database
                    ZedGraph.ControlTest.NorthwindDataSetTableAdapters.OrdersTableAdapter adapter =
                                new ZedGraph.ControlTest.NorthwindDataSetTableAdapters.OrdersTableAdapter();
                    // Create a DataTable and fill it with data from the database
                    ZedGraph.ControlTest.NorthwindDataSet.OrdersDataTable table = adapter.GetData();

                    //NorthwindDataSet ds = ZedGraph.ControlTest.NorthwindDataSet;
                    //DataTable dt = ds.Tables["Orders"];
                    //dt.Select( "SELECT *" );

                    //DataTable dt = ds.Tables[
                    //dt.

                    //string strConn = "Provider=SQLOLEDB;Data Source=(local)\\NetSDK;" +
                    //		"Initial Catalog=Northwind;Trusted_Connection=Yes;";
                    //string strSQL = "SELECT CustomerID, CompanyName, ContactName, Phone " +
                    //		"FROM Customers";
                    //OleDbDataAdapter da = new OleDbDataAdapter( strSQL, strConn );
                    //DataSet ds = new DataSet();
                    //da.Fill( ds, "Customers" );

                    //			string cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Northwind.mdb;Persist Security Info=False";
                    //			string sql = "SELECT * FROM Orders";
                    //			OleDbConnection con = new OleDbConnection( cn );
                    //			OleDbDataAdapter adapt = new OleDbDataAdapter();
                    //			adapt.SelectCommand = new OleDbCommand( sql, con );

                    //			DataSet ds = new DataSet(); ;
                    //DataTable dt = new DataTable();

                    //			adapt.Fill( ds, "Orders" );

                    // Specify the table as the data source
                    dspl.DataSource = table;
                    // The X data will come from the "OrderDate" column
                    dspl.XDataMember = "OrderDate";
                    // The Y data will come from the "Freight" column
                    dspl.YDataMember = "Freight";
                    // The Z data are not used
                    dspl.ZDataMember = null;
                    // The Tag data will come from the "ShipName" column
                    // (note that this will just set PointPair.Tag = ShipName)
                    dspl.TagDataMember = "ShipName";

                    //List<Sample> sampleList = new List<Sample>();

                    //ArrayList arrayList = new ArrayList();
                    //DateTime dt = new DateTime( 2006, 3, 1 );
                    //for ( int i = 0; i < 50; i++ )
                    //{
                    //	double x = i;
                    //	double y = Math.Sin( i / 5 );
                    //	Sample sample = new Sample();
                    //	sample.Time = dt.AddDays( i );
                    //	sample.Position = x;
                    //	sample.Velocity = y;
                    //arrayList.Add( sample );
                    //	sampleList.Add( sample );
                    //}

                    //dspl.DataSource = sampleList;
                    //dspl.XDataMember = "Time";
                    //dspl.YDataMember = "Position";
                    //dspl.ZDataMember = "Velocity";
                    //dspl.TagDataMember = null;

                    //int count = table.Count;

                    // X axis will be dates
                    z1.GraphPane.XAxis.Type = AxisType.Date;

                    // Make a curve
                    LineItem myCurve = z1.GraphPane.AddCurve( "Orders", dspl, Color.Blue );
                    // Turn off the line so it's a scatter plot
                    myCurve.Line.IsVisible = false;

                    // Show the point values.  These are derived from the "ShipName" database column,
                    // which is set as the "Tag" property.
                    z1.IsShowPointValues = true;

                    // Auto set the scale ranges
                    z1.AxisChange();
                }
        */
        private void CreateGraph_DataSourcePointList( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.MasterPane[0];

            myPane.Title.Text = "Statistics";
            myPane.XAxis.Title.Text = "Job";
            myPane.Y2Axis.Title.Text = "Count";

            DataSourcePointList dsp = new DataSourcePointList();

            //Person bllPerson = new Person();

            DataTable dt = new DataTable();
            dt.Columns.Add( "Job", typeof( string ) );
            dt.Columns.Add( "Count", typeof( Int32 ) );
            DataRow dr = dt.NewRow();
            dr["Job"] = 1;
            dr["Count"] = 100;

            dt.Rows.Add( dr );
            dsp.DataSource = dt;
            dsp.XDataMember = "Job";
            dsp.YDataMember = "Count";
            dsp.ZDataMember = null;
            dsp.TagDataMember = "Job";

            myPane.XAxis.Type = AxisType.Text;

            BarItem myBar = myPane.AddBar( "Statistics", dsp, Color.Blue );

            z1.AxisChange();
        }
示例#11
0
        public void chartview(DataTable tablechart, List<Color> colorchart)
        {
            // Edit by binhpro 19/10/2012
            _startDate = fromdateTextBox.Text.ToDateTimeTryParse(null);
            _endDate = todateTextBox.Text.ToDateTimeTryParse(null);
            // fix datetime
            if (_startDate != null)
            {
                _startDate = new DateTime(_startDate.Value.Year, _startDate.Value.Month, _startDate.Value.Day, 0, 0, 0);
            }
            if(_endDate != null)
            {
                _endDate = new DateTime(_endDate.Value.Year, _endDate.Value.Month, _endDate.Value.Day,23,59,59);
            }

            for (int i = 0; i < sensorinchart; i++)
            {
                int idsen = Convert.ToInt16(tablechart.Rows[i]["SensorID"]);
                List<SensorValue> listvalue = entityConntext.SensorValues.Where(ent =>
                    ent.SensorID == idsen &&
                    (_startDate == null || ent.MeaTime >= _startDate) &&
                    (_endDate == null || ent.MeaTime <= _endDate)
                    ).OrderBy(ent => ent.MeaTime).ToList();

                DataSourcePointList dsp = new DataSourcePointList();
                dsp.DataSource = listvalue;
                if (Convert.ToInt16(tablechart.Rows[i]["TypeofValue"]) == 0)
                {
                    dsp.YDataMember = "RawValue";
                }
                if (Convert.ToInt16(tablechart.Rows[i]["TypeofValue"]) == 1)
                {
                    dsp.YDataMember = "CalcValue";
                }
                dsp.XDataMember = "MeaTime";

                LineItem mycurve = myPane.AddCurve(Convert.ToString(tablechart.Rows[i]["SensorName"]), dsp, colorchart[i], SymbolType.Circle);
                mycurve.Line.Width = tablechart.Rows[i]["BoldLine"].ToInt32TryParse();

                switch (tablechart.Rows[i]["LineStyle"].ToInt32TryParse())
                {
                    case 0:
                        mycurve.Line.Style = DashStyle.Solid;
                        break;
                    case 1:
                        mycurve.Line.Style = DashStyle.Dot;
                        break;
                    case 2:
                        mycurve.Line.Style = DashStyle.Dash;
                        break;
                    case 3:
                        mycurve.Line.Style = DashStyle.DashDot;
                        break;
                    case 4:
                        mycurve.Line.Style = DashStyle.DashDotDot;
                        break;
                }
                //mycurve.Line.Style = (DashStyle)tablechart.Rows[i]["LineStyle"];

            }
            //myPane.
            zedGraphChart.IsShowPointValues = true;

            //lenh hien thi chart
            zedGraphChart.AxisChange();
            zedGraphChart.Invalidate();
            zedGraphChart.Refresh();
        }