コード例 #1
0
ファイル: AqHistories.xaml.cs プロジェクト: MrMYHuang/taq
        public int aqVals2Coll(List <double> aqVals, int updateHour, string updateDate)
        {
            for (var h = 0; h < 24; h++)
            {
                var rotHour = (24 + updateHour - h) % 24;
                var aqVal   = aqVals[rotHour];
                // This ugly coding style comes from a problem that the chart doesn't update its Hour axis anymore after the first assignment to Hour.
                if (rotHour == 0)
                {
                    aq24HrValColl.Add(new Aq24HrVal
                    {
                        // Replace Hour 0 with date.
                        Hour = updateDate.Replace("-", "/"),
                        Val  = aqVal
                    });
                }
                else
                {
                    aq24HrValColl.Add(new Aq24HrVal
                    {
                        Hour = rotHour + "",
                        Val  = aqVal
                    });
                }
                var aqLevel = StaticTaqModel.getAqLevel(AqHistShared.aqName, aqVal);
                //aq24HrValColl.Where(hv => hv.Hour == "0").First().Hour = updateDate.Replace("-", "/");
                aqColors.Add(new SolidColorBrush(StaticTaqModelView.html2RgbColor(StaticTaqModel.aqColors[AqHistShared.aqName][aqLevel])));
            }
            ccm.CustomBrushes = aqColors;

            return(0);
        }
コード例 #2
0
        public AqColorMaps()
        {
            app = App.Current as App;
            this.InitializeComponent();
            aqLimitsColl = new ObservableCollection <AqLimits>();
            var aqLevelCnt = StaticTaqModel.aqiLimits.Count;

            foreach (var aqName in apNames)
            {
                var aqLimit = new AqLimits
                {
                    Name   = aqName,
                    Limits = new ObservableCollection <double>(),
                    Diffs  = new ObservableCollection <double>()
                };

                // Skip aqLimits[aqName][0], because it is unused -1.
                aqLimit.Limits.Add(StaticTaqModel.aqLimits[aqName][1]);
                aqLimit.Diffs.Add(StaticTaqModel.aqLimits[aqName][1]);
                for (var i = 2; i < aqLevelCnt; i++)
                {
                    aqLimit.Limits.Add(StaticTaqModel.aqLimits[aqName][i]);
                    aqLimit.Diffs.Add(StaticTaqModel.aqLimits[aqName][i] - StaticTaqModel.aqLimits[aqName][i - 1]);
                }
                aqLimitsColl.Add(aqLimit);
            }
            for (var i = 1; i < aqLevelCnt; i++)
            {
                var sbs = new StackingColumn100Series();
                sbs.Interior = new SolidColorBrush(StaticTaqModelView.html2RgbColor(StaticTaqModel.aqiBgColors[i]));

                sbs.XBindingPath = "Name";
                sbs.YBindingPath = "Diffs[" + i + "]";

                var b = new Binding();
                b.Source = this;
                b.Path   = new PropertyPath("aqLimitsColl");
                b.Mode   = BindingMode.OneWay;
                sbs.SetBinding(StackingBarSeries.ItemsSourceProperty, b);

                var cai = new ChartAdornmentInfo();
                cai.SegmentLabelContent = LabelContent.LabelContentPath;
                // DataContext =\"aqLimitsColl[" + i + "].\"
                var textColor = "Black";
                if (i > StaticTaqModel.aqTextColorLimit)
                {
                    textColor = "White";
                }
                var dt = XamlReader.Load($"<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
                                         "<TextBlock Foreground=\"" + textColor + "\" Text=\"{Binding Converter={StaticResource con}}\"></TextBlock></DataTemplate>") as DataTemplate;
                cai.LabelTemplate = dt;
                cai.LabelPosition = AdornmentsLabelPosition.Inner;
                cai.ShowLabel     = true;

                sbs.AdornmentsInfo = cai;
                sbs.SegmentSpacing = 0;

                sfChart.Series.Add(sbs);
            }

            this.DataContext = this;
        }