Example #1
0
        public static Color GetRadomColor(CurveInfoList infoList)
        {
            Color  color   = Color.Black;
            Random ran     = new Random();
            bool   bFinded = false;

            while (!bFinded)
            {
                int r = ran.Next(0, 255);
                int g = ran.Next(0, 255);
                int b = ran.Next(0, 255);
                color = Color.FromArgb(r, g, b);
                if (!infoList.hasColor(color))
                {
                    bFinded = true;
                }
            }
            return(color);
        }
Example #2
0
        void HelperInvoke(int index, int nodeID, int humi, int temp)
        {
            //CurveInfo tempInfo = humiCurveInfo;
            CurveInfo     tempInfo = null;
            CurveInfoList tempList = null;

            this.zedGraphControl1.GraphPane.XAxis.Scale.MaxAuto = true;
            //this.zedGraphControl1.GraphPane.XAxis.Scale.Max
            double y = humi;

            switch (comboBox1.SelectedIndex)
            {
            case 0:    //湿度
                y = humi;
                //tempInfo = humiCurveInfo;
                tempList = humiCurveInfoList;
                tempInfo = humiCurveInfoList.getCurveInfoByNodeID(nodeID);
                if (tempInfo == null)
                //如果当前节点尚未建立
                {
                    Color     color = CurveInfoList.GetRadomColor(humiCurveInfoList);
                    CurveInfo ciNew = new CurveInfo(nodeID, "节点" + nodeID.ToString(), color);
                    humiCurveInfoList.addNode(ciNew);
                    this.AddHumidityCurve();
                    tempInfo = ciNew;
                }
                break;

            case 1:    //温度
                y        = temp;
                tempList = tempetureCurveInfoList;
                //tempInfo = tempCurveInfo;
                tempInfo = tempetureCurveInfoList.getCurveInfoByNodeID(nodeID);
                if (tempInfo == null)
                {
                    Color     color = CurveInfoList.GetRadomColor(tempetureCurveInfoList);
                    CurveInfo ciNew = new CurveInfo(nodeID, "节点" + nodeID.ToString(), color);
                    tempetureCurveInfoList.addNode(ciNew);
                    this.AddTemperatureCurve();
                    tempInfo = ciNew;
                }
                break;
            }
            double x = (double)new XDate(DateTime.Now);

            //pointPairList.Add(x, y);
            tempInfo.AddPoint(x, y);
            this.zedGraphControl1.AxisChange();
            this.zedGraphControl1.Refresh();
            int maxPoint = 20;

            foreach (CurveInfo ci in tempList)
            {
                ci.AddPoint(x, double.MaxValue);
                if (ci.PointPairList.Count > maxPoint)
                {
                    //ci.PointPairList.RemoveAt(0);
                    int sub = ci.PointPairList.Count - maxPoint;
                    if (sub > 0)
                    {
                        ci.PointPairList.RemoveRange(0, sub);
                    }
                }
            }
            //if (tempInfo.PointPairList.Count >= 10)
            //{
            //tempInfo.PointPairList.RemoveAt(0);
            //}
            //if (pointPairList.Count >= 50)
            //{
            //    pointPairList.RemoveAt(0);
            //}
        }