public List <DateTime> getTimeValue(string classroomID) { List <string[]> temperatureValue = new BLL.Environment().getValue(classroomID, "温度传感器"); List <DateTime> lsTime = new List <DateTime>(); foreach (string[] str in temperatureValue) { lsTime.Add(Convert.ToDateTime(str[1])); } return(lsTime); }
public List <string> getTemperatureValue(string classroomID) { List <string[]> temperatureValue = new BLL.Environment().getValue(classroomID, "温度传感器"); List <string> cherry = new List <string>(); foreach (string[] str in temperatureValue) { cherry.Add(str[0]); } return(cherry); }
public List <string> getHumidityValue(string classroomID) { List <string[]> humidityValue = new BLL.Environment().getValue(classroomID, "湿度传感器"); List <string> pineapple = new List <string>(); foreach (string[] str in humidityValue) { pineapple.Add(str[0]); } return(pineapple); }
public void CreateChartSpline(string name = null, List <DateTime> LsTime = null, List <string> cherry1 = null, List <string> pineapple1 = null) { List <string[]> temperatureValue = new BLL.Environment().getValue(classroomID, "温度传感器"); List <string[]> humidityValue = new BLL.Environment().getValue(classroomID, "湿度传感器"); List <DateTime> lsTime = new List <DateTime>(); List <string> cherry = new List <string>(); List <string> pineapple = new List <string>(); foreach (string[] str in temperatureValue) { lsTime.Add(Convert.ToDateTime(str[1])); cherry.Add(str[0]); } foreach (string[] str in humidityValue) { pineapple.Add(str[0]); } //创建一个图标 Chart chart = new Chart(); //设置图标的宽度和高度 chart.Width = chartGrid.Width; chart.Height = chartGrid.Height; chart.Margin = new Thickness(0, 0, 0, 0); //是否启用打印和保持图片 chart.ToolBarEnabled = false; //设置图标的属性 chart.ScrollingEnabled = false; //是否启用或禁用滚动 chart.View3D = false; //3D效果显示 //创建一个标题的对象 Title title = new Title(); //设置标题的名称 title.Text = "温湿度曲线图"; title.Padding = new Thickness(0, 10, 5, 0); chart.Background = new SolidColorBrush(Color.FromArgb(100, 100, 100, 100)); //向图标添加标题 chart.Titles.Add(title); //X轴 //初始化一个新的Axis Axis xaxis = new Axis(); //设置Axis的属性 //图表的X轴坐标按什么来分类,如时分秒 xaxis.IntervalType = IntervalTypes.Hours; //图表的X轴坐标间隔如2,3,20等,单位为xAxis.IntervalType设置的时分秒。 xaxis.Interval = 1; //设置X轴的时间显示格式为7-10 11:20 xaxis.ValueFormatString = "HH:00"; //给图标添加Axis chart.AxesX.Add(xaxis); //Y轴 Axis yAxis = new Axis(); //设置图标中Y轴的最小值为-20 yAxis.AxisMinimum = -20; //设置图标中Y轴的最大值为100 yAxis.AxisMaximum = 100; //设置间隔为10 yAxis.Interval = 10; //设置图表中Y轴的后缀 yAxis.Suffix = "℃"; chart.AxesY.Add(yAxis); // 创建一个新的数据线。 DataSeries dataSeries = new DataSeries(); // 设置数据线的格式。 dataSeries.LegendText = "温度"; dataSeries.RenderAs = RenderAs.Spline;//折线图 dataSeries.XValueType = ChartValueTypes.DateTime; // 设置数据点 DataPoint dataPoint; for (int i = 0; i < cherry.Count; i++) { // 创建一个数据点的实例。 dataPoint = new DataPoint(); // 设置X轴点 dataPoint.XValue = lsTime[i]; //设置Y轴点 dataPoint.YValue = double.Parse(cherry[i]); dataPoint.MarkerSize = 8; //dataPoint.Tag = tableName.Split('(')[0]; //设置数据点颜色 // dataPoint.Color = new SolidColorBrush(Colors.LightGray); //dataPoint.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown); //添加数据点 dataSeries.DataPoints.Add(dataPoint); } // 添加数据线到数据序列。 chart.Series.Add(dataSeries); // 创建一个新的数据线。 DataSeries dataSeriesPineapple = new DataSeries(); // 设置数据线的格式。 dataSeriesPineapple.LegendText = "湿度"; dataSeriesPineapple.RenderAs = RenderAs.Spline;//折线图 dataSeriesPineapple.XValueType = ChartValueTypes.DateTime; // 设置数据点 DataPoint dataPoint2; for (int i = 0; i < pineapple.Count; i++) { // 创建一个数据点的实例。 dataPoint2 = new DataPoint(); // 设置X轴点 dataPoint2.XValue = lsTime[i]; //设置Y轴点 dataPoint2.YValue = double.Parse(pineapple[i]); dataPoint2.MarkerSize = 8; //dataPoint2.Tag = tableName.Split('(')[0]; //设置数据点颜色 // dataPoint.Color = new SolidColorBrush(Colors.LightGray); //dataPoint2.MouseLeftButtonDown += new MouseButtonEventHandler(dataPoint_MouseLeftButtonDown); //添加数据点 dataSeriesPineapple.DataPoints.Add(dataPoint2); } // 添加数据线到数据序列。 chart.Series.Add(dataSeriesPineapple); //将生产的图表增加到Grid,然后通过Grid添加到上层Grid. Grid gr = new Grid(); gr.Children.Add(chart); chartGrid.Children.Add(gr); }