Beispiel #1
0
        public void UpdateChart()
        {
            this.Config.Options.Title.Text = $"Zmienna lingwistyczna {this.parent_variable.Name}: {this.parent_variable.Description}";
            LinearCartesianAxis lca = this.Config.Options.Scales.xAxes[0] as LinearCartesianAxis;

            lca.Ticks.Min = this.parent_variable.Minimum.Value;
            lca.Ticks.Max = this.parent_variable.Maximum.Value;

            this.Config.Data.Datasets.Clear();

            string[] colors = new[] { "blue", "red", "green", "black", "magenta", "cyan", "brown", "yellow" };
            int      icolor = 0;

            foreach (FuzzyValue fval in this.parent_variable.Values)
            {
                LineDataset <Point> data_set = new LineDataset <Point>
                {
                    Label          = fval.Name,
                    LineTension    = 0,
                    PointRadius    = 2,
                    BorderColor    = colors[icolor++ % colors.Length],
                    PointHitRadius = 10,
                    BorderWidth    = 3,
                };

                if (fval.MembershipType == MembershipFunctionFamily.Trapezoidal)
                {
                    NamedParameter sl = fval.GetParameter("SuppL");
                    NamedParameter kl = fval.GetParameter("KernL");
                    NamedParameter kr = fval.GetParameter("KernR");
                    NamedParameter sr = fval.GetParameter("SuppR");

                    data_set.Add(new Point(this.parent_variable.Minimum.Value, 0));
                    data_set.Add(new Point(sl.Value, 0));
                    data_set.Add(new Point(kl.Value, 1));
                    data_set.Add(new Point(kr.Value, 1));
                    data_set.Add(new Point(sr.Value, 0));
                    data_set.Add(new Point(this.parent_variable.Maximum.Value, 0));

                    this.Config.Data.Datasets.Add(data_set);
                }
            }
        }
Beispiel #2
0
        protected override void OnInitialized()
        {
            if (Day == MyChartType.Hourly)
            {
                _config = new LineConfig
                {
                    Options = new LineOptions
                    {
                        Title = new OptionsTitle
                        {
                            Display = true,
                            Text    = Title + " Last Day"
                        },
                        Responsive = true,
                        Animation  = new ArcAnimation
                        {
                            AnimateRotate = true,
                            AnimateScale  = true
                        },
                        Scales = new Scales
                        {
                            xAxes = new List <CartesianAxis>
                            {
                                new TimeAxis
                                {
                                    Distribution = TimeDistribution.Linear,
                                    Ticks        = new TimeTicks
                                    {
                                        Source  = TickSource.Auto,
                                        Reverse = true
                                    },
                                    Time = new TimeOptions
                                    {
                                        Unit           = TimeMeasurement.Hour,
                                        Round          = TimeMeasurement.Second,
                                        TooltipFormat  = "DD.MM.YYYY HH:mm:ss",
                                        DisplayFormats = TimeDisplayFormats.DE_CH
                                    },

                                    ScaleLabel = new ScaleLabel
                                    {
                                        LabelString = "Time"
                                    }
                                }
                            }
                        }
                    }
                };
            }
            else if (Day == MyChartType.Daily)
            {
                _config = new LineConfig
                {
                    Options = new LineOptions
                    {
                        Title = new OptionsTitle
                        {
                            Display = true,
                            Text    = Title + " Last 2 Weeks"
                        },
                        Responsive = true,
                        Animation  = new ArcAnimation
                        {
                            AnimateRotate = true,
                            AnimateScale  = true
                        },
                        Scales = new Scales
                        {
                            xAxes = new List <CartesianAxis>
                            {
                                new TimeAxis
                                {
                                    Distribution = TimeDistribution.Linear,
                                    Ticks        = new TimeTicks
                                    {
                                        Source  = TickSource.Auto,
                                        Reverse = true
                                    },
                                    Time = new TimeOptions
                                    {
                                        Unit           = TimeMeasurement.Day,
                                        Round          = TimeMeasurement.Hour,
                                        TooltipFormat  = "DD.MM.YYYY",
                                        DisplayFormats = TimeDisplayFormats.DE_CH
                                    },

                                    ScaleLabel = new ScaleLabel
                                    {
                                        LabelString = "Date"
                                    }
                                }
                            }
                        }
                    }
                };
            }
            else
            {
                _config = new LineConfig
                {
                    Options = new LineOptions
                    {
                        Title = new OptionsTitle
                        {
                            Display = true,
                            Text    = Title + " Monthly"
                        },
                        Responsive = true,
                        Animation  = new ArcAnimation
                        {
                            AnimateRotate = true,
                            AnimateScale  = true
                        },
                        Scales = new Scales
                        {
                            xAxes = new List <CartesianAxis>
                            {
                                new TimeAxis
                                {
                                    Distribution = TimeDistribution.Linear,
                                    Ticks        = new TimeTicks
                                    {
                                        Source  = TickSource.Auto,
                                        Reverse = true
                                    },
                                    Time = new TimeOptions
                                    {
                                        Unit           = TimeMeasurement.Month,
                                        Round          = TimeMeasurement.Day,
                                        TooltipFormat  = "DD.MM.YYYY",
                                        DisplayFormats = TimeDisplayFormats.DE_CH
                                    },

                                    ScaleLabel = new ScaleLabel
                                    {
                                        LabelString = "Date"
                                    }
                                }
                            }
                        }
                    }
                };
            }

            var Set = new LineDataset <TimeTuple <decimal> >
            {
                BackgroundColor  = ColorUtil.FromDrawingColor(Color.Blue),
                BorderColor      = ColorUtil.FromDrawingColor(Color.Blue),
                Fill             = false,
                BorderWidth      = 1,
                PointRadius      = 5,
                PointBorderWidth = 1,
                SteppedLine      = SteppedLine.False,
                ShowLine         = true,
                Label            = "Current"
            };

            var PrevSet = new LineDataset <TimeTuple <decimal> >
            {
                BackgroundColor  = ColorUtil.FromDrawingColor(Color.LightBlue),
                BorderDash       = new int[] { 10, 5 },
                BorderColor      = ColorUtil.FromDrawingColor(Color.LightBlue),
                Fill             = false,
                BorderWidth      = 1,
                PointRadius      = 3,
                PointBorderWidth = 1,
                SteppedLine      = SteppedLine.False,
                ShowLine         = true,
                Label            = "Previous"
            };

            for (int i = 0; i < Data.Count; i++)
            {
                var s      = Labels[i];
                var points = new TimeTuple <decimal>(new Moment(s), Convert.ToDecimal(Data[i]));
                Set.Add(points);
            }

            for (int i = 0; i < (Data.Count < PrevData.Count ? Data.Count : PrevData.Count); i++)
            {
                var s      = Labels[i];
                var points = new TimeTuple <decimal>(new Moment(s), Convert.ToDecimal(PrevData[i]));
                PrevSet.Add(points);
            }

            if (Labels.Count > 0)
            {
                DateTime dt = Labels.OrderByDescending(s => s.Date).FirstOrDefault();
                Set.Label = dt.ToString("yyyy-MM-dd");
                if (Day == MyChartType.Hourly)
                {
                    PrevSet.Label = dt.AddDays(-1).ToString("yyyy-MM-dd");
                }
                else if (Day == MyChartType.Daily)
                {
                    PrevSet.Label = dt.AddDays(-14).ToString("yyyy-MM-dd");
                }
                else
                {
                    PrevSet.Label  = "N/A";
                    PrevSet.Hidden = true;
                }
            }

            _config.Data.Datasets.Add(Set);
            _config.Data.Datasets.Add(PrevSet);
        }
Beispiel #3
0
        public Charter(string keyword, GraphData data, string xLabel, string yLabel, bool reverse, int min, int max)
        {
            Data = data;

            _lineConfig = new LineConfig
            {
                Options = new LineOptions
                {
                    Responsive = true,
                    Title      = new OptionsTitle
                    {
                        Display = true,
                        Text    = keyword
                    },
                    Legend = new Legend
                    {
                        Display = false
                    },
                    Tooltips = new Tooltips
                    {
                        Mode      = InteractionMode.Nearest,
                        Intersect = false
                    },
                    Scales = new Scales
                    {
                        yAxes = new List <CartesianAxis>
                        {
                            new LinearCartesianAxis
                            {
                                ScaleLabel = new ScaleLabel
                                {
                                    LabelString = yLabel
                                },
                                Ticks = new LinearCartesianTicks
                                {
                                    Reverse = reverse,
                                    Min     = min,
                                    Max     = max
                                },
                            },
                        },
                        xAxes = new List <CartesianAxis>
                        {
                            new TimeAxis
                            {
                                Distribution = TimeDistribution.Linear,
                                Ticks        = new TimeTicks
                                {
                                    Source = TickSource.Data
                                },
                                Time = new TimeOptions
                                {
                                    Unit           = TimeMeasurement.Day,
                                    Round          = TimeMeasurement.Day,
                                    TooltipFormat  = "MM.DD.YYYY",
                                    DisplayFormats = TimeDisplayFormats.DE_CH
                                },
                                ScaleLabel = new ScaleLabel
                                {
                                    LabelString = xLabel
                                }
                            }
                        }
                    },
                    Hover = new LineOptionsHover
                    {
                        Intersect = true,
                        Mode      = InteractionMode.Y
                    }
                }
            };

            _WeightDataSet = new LineDataset <TimeTuple <int> >
            {
                BackgroundColor  = ColorUtil.FromDrawingColor(System.Drawing.Color.White),
                BorderColor      = ColorUtil.FromDrawingColor(System.Drawing.Color.Red),
                Label            = yLabel,
                Fill             = false,
                BorderWidth      = 2,
                PointRadius      = 2,
                PointBorderWidth = 2,
                SteppedLine      = SteppedLine.False,
                Hidden           = false
            };

            _WeightDataSet.RemoveAll(e => true);

            //data.Shuffle();
            for (int i = 0; i < Data.Positions.Count; i++)
            {
                var pos  = Data.Positions[i];
                var date = Data.Dates[i];
                _WeightDataSet.Add(new TimeTuple <int>(new Moment(date), pos));
            }

            _lineConfig.Data.Datasets.Clear();
            _lineConfig.Data.Datasets.Add(_WeightDataSet);
            _lineChartJs.Update();
        }