示例#1
0
        public async Task <ChartJSdataset> GetData(ChartJS mychart = null)
        {
            Dictionary <string, KeyValuePair <double, int> > winrate = new Dictionary <string, KeyValuePair <double, int> >();
            Dictionary <string, Dictionary <string, KeyValuePair <double, int> > > winratevs = new Dictionary <string, Dictionary <string, KeyValuePair <double, int> > >();

            List <string> labels = new List <string>();
            List <double> wr     = new List <double>();

            string info;
            await Task.Run(() => { _dsdata.GetDynData(_options, out winrate, out winratevs, out info); });

            ChartJSdataset dataset = new ChartJSdataset();

            if (_options.Interest == "")
            {
                foreach (string race in s_races_ordered)
                {
                    if (winrate.ContainsKey(race) && winrate[race].Value > 0)
                    {
                        wr.Add(winrate[race].Key);
                        labels.Add(race + " (" + winrate[race].Value.ToString() + ")");
                    }
                    else
                    {
                        //wr.Add(0);
                        //labels.Add(race + " (0)");
                    }
                }
                dataset.label = "global";
            }
            else
            {
                foreach (string race in s_races_ordered)
                {
                    if (winratevs[_options.Interest].ContainsKey(race) && winratevs[_options.Interest][race].Value > 0)
                    {
                        wr.Add(winratevs[_options.Interest][race].Key);
                        labels.Add(race + " (" + winratevs[_options.Interest][race].Value.ToString() + ")");
                    }
                    else
                    {
                        //wr.Add(0);
                        //labels.Add(race + "(0)");
                    }
                }
                dataset.label = _options.Interest;
            }
            dataset.data = wr.ToArray();
            if (mychart != null)
            {
                mychart.data.labels = labels.ToArray();
                mychart.data.datasets.Add(dataset);
            }
            return(dataset);
        }
示例#2
0
        public async Task <ChartJS> AddDataset(ChartJSdataset dataset)
        {
            var col = GetRandomChartColor();

            dataset.backgroundColor.Add("rgba(0, 0, 0, 0)");
            dataset.borderColor          = col.borderColor;
            dataset.pointBackgroundColor = col.pointBackgroundColor;
            mychart.data.datasets.Add(dataset);
            await _jsIterop.AddDataset(JsonSerializer.Serialize(dataset));

            return(mychart);
        }