public override void TextChange() { TimeSpan BartimeSpan = DateTime.Now.Subtract(TTime); if (BartimeSpan.TotalMilliseconds >= 60000) { Month_ElectricTotal(); int Index = 0; foreach (var ElectricConfigitem in ElectricConfigs) { MonthchartControl.Series[Index].DataSource = ElectricTotals.Where(g => g.GatewayIndex == ElectricConfigitem.GatewayIndex & g.DeviceIndex == ElectricConfigitem.DeviceIndex).ToList(); Index++; } MonthchartControl.Refresh(); } foreach (var item in Field4UserControls) { item.TextChange(); } }
public MainUserControl(MysqlMethod mysql, List <AbsProtocol> electricAbsprotocols) { InitializeComponent(); MysqlMethod = mysql; ElectricAbsProtocols = electricAbsprotocols; GatewayConfigs = MysqlMethod.Search_GatewayConfig(); foreach (var Gatewayitem in GatewayConfigs) { var configs = MysqlMethod.Search_ElectricConfig(Gatewayitem.GatewayIndex); foreach (var Configitem in configs) { ElectricConfigs.Add(Configitem); } } #region 月累積量 Month_ElectricTotal(); foreach (var ElectricConfigitem in ElectricConfigs) { Series series = new Series($"{ElectricConfigitem.DeviceName}", viewType: ViewType.Bar); series.DataSource = ElectricTotals.Where(g => g.GatewayIndex == ElectricConfigitem.GatewayIndex & g.DeviceIndex == ElectricConfigitem.DeviceIndex).ToList(); series.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd} " + "\n" + "用電量:{V:0.00}kWh"; series.LegendTextPattern = "{A}"; series.ArgumentDataMember = "ttimen"; series.ValueDataMembers.AddRange(new string[] { "KwhTotal" }); series.CheckedInLegend = true; ((BarSeriesLabel)series.Label).ShowForZeroValues = true; MonthchartControl.Series.Add(series); } MonthchartControl.LegendItemChecked += (s, e) => //曲線圖 Series勾選功能 { Series checkedSeries = e.CheckedElement as Series; if (checkedSeries == null || Series.IndexOf(checkedSeries) != othersSeriesIndex) { return; } for (int i = 0; i < Series.Count; i++) { if (i < othersSeriesIndex) { Series[i].Visible = e.NewCheckState; } } }; MonthchartControl.Legend.MarkerMode = LegendMarkerMode.CheckBox; MonthchartControl.Legend.Border.Visibility = DefaultBoolean.False; MonthchartControl.Legend.BackColor = Color.Transparent; MonthchartControl.Legend.Direction = LegendDirection.BottomToTop; MonthchartControl.CrosshairOptions.CrosshairLabelMode = CrosshairLabelMode.ShowCommonForAllSeries; MonthchartControl.CrosshairOptions.LinesMode = CrosshairLinesMode.Auto; MonthchartControl.CrosshairOptions.ShowArgumentLabels = true; XYDiagram diagram = (XYDiagram)MonthchartControl.Diagram; diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Day; // 顯示設定 diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day; // 刻度設定 diagram.AxisX.WholeRange.SideMarginsValue = 1; //不需要邊寬 #endregion #region 分電表顯示 int ElectricInt = 0; foreach (var ElectricConfigitem in ElectricConfigs) { ElectricUserControl electric = new ElectricUserControl(ElectricConfigitem, mysql, ElectricAbsProtocols) { Location = new Point(5 + (ElectricInt * 855), 5) }; ElectricpanelControl.Controls.Add(electric); Field4UserControls.Add(electric); ElectricInt++; } #endregion }