Пример #1
0
        public static SamplesResult NewMethod4()
        {
            var url = @"https://vega.github.io/vega-datasets/data/stocks.csv";

            var cond = Vega.Condition()
                       .AddTest(d => d.Number("price") > 400)
                       .AddValue(Color.Red);


            var cm = Vega.SetData(url)
                     .SetEncoding(en =>
            {
                en.X     = Vega.PcField().SetName("date:T");
                en.Y     = Vega.PcField().SetName("price:Q");
                en.Color = cond.ToColor(Color.Blue);
            })
                     .SetFilter(d => d.String("symbol") == "GOOG")
            ;

            var line  = cm.SetMark(Vega.Marks.Line);
            var point = cm.SetMark(Vega.Marks.Point);

            return(new SamplesResult
            {
                Desc = "设置条件,价格高于400的,点图中的点会设置为红色",
                Html = (line + point).ToHtml()
            });
        }
Пример #2
0
        public static SamplesResult NewMethod6()
        {
            var url = @"https://vega.github.io/vega-datasets/data/cars.json";

            var selection = Vega.IntervalSelection("pts")
                            .SetBind(IntervalSelectionBind.Scales);

            var cond = Vega.Condition()
                       .AddFiled(Vega.PcField("Origin:N"))
                       .AddSelection(selection);


            var cm = Vega.SetData(url)
                     .SetMark(Vega.Marks.Point)
                     .SetEncoding(en =>
            {
                en.Y     = Vega.PcField().SetName("Horsepower:Q");
                en.Color = cond.ToColor(Color.Gray);
            })
                     .SetSelection(selection);

            var left  = cm.SetEncoding(en => en.X = Vega.PcField("Acceleration:Q"));
            var right = cm.SetEncoding(en => en.X = Vega.PcField("Miles_per_Gallon:Q"));

            return(new SamplesResult
            {
                Desc = @"2个表相同的y轴,不同的x轴。
能用鼠标点击拖动移动图表显示范围,用滚轮放大或缩小范围。
并且2个表是同步更新",
                Html = (left | right).ToHtml()
            });
        }
Пример #3
0
        public static SamplesResult NewMethod7()
        {
            var url = @"https://vega.github.io/vega-datasets/data/cars.json";
            //设置范围选择
            var selection = Vega.IntervalSelection("pts");
            //设置条件
            var cond = Vega.Condition()
                       .AddFiled(Vega.PcField("Origin:N"))
                       .AddSelection(selection);

            var cm = Vega.SetData(url)          //数据
                     .SetMark(Vega.Marks.Point) // 图表形状
                     .SetEncoding(en =>         //数据对应
            {
                en.Y     = Vega.PcField("Horsepower:Q");
                en.Color = cond.ToColor(Color.Gray);
            })
                     .SetSelection(selection);

            var left  = cm.SetEncoding(en => en.X = Vega.PcField("Acceleration:Q"));
            var right = cm.SetEncoding(en => en.X = Vega.PcField("Miles_per_Gallon:Q"));

            //左右2张图
            return(new SamplesResult
            {
                Desc = @"范围选择,鼠标左键点击可画出范围框,然后点击框能拖动。
框范围内正常颜色,其他为灰色",
                Html = (left | right).ToHtml()
            });
        }
Пример #4
0
        public static SamplesResult NewMethod5()
        {
            var url = @"https://vega.github.io/vega-datasets/data/cars.json";

            var selection = Vega.SingleSelection("pts").SetOn("mouseover");


            var cond = Vega.Condition()
                       .AddFiled(Vega.PcField().SetAggregate("count").SetType(FieldType.Quantitative))
                       .AddSelection(selection);


            var cm = Vega.SetData(url)
                     .SetEncoding(en =>
            {
                en.X     = Vega.PcField().SetName("Origin:O");
                en.Y     = Vega.PcField().SetName("Cylinders:O");
                en.Color = cond.ToColor(Color.Gray);
            })
                     .SetSelection(selection);

            var rect = cm.SetMark(Vega.Marks.Rect);

            return(new SamplesResult
            {
                Desc = "鼠标经过,高亮颜色,其他地方灰色",
                Html = rect.ToHtml()
            });
        }
Пример #5
0
        private static void NewMethod7()
        {
            var url = @"https://vega.github.io/vega-datasets/data/cars.json";
            //设置范围选择
            var selection = Vega.IntervalSelection("pts");
            //设置条件
            var cond = Vega.Condition()
                       .AddFiled(Vega.PcField("Origin:N"))
                       .AddSelection(selection);

            var cm = Vega.SetData(url)          //数据
                     .SetMark(Vega.Marks.Point) // 图表形状
                     .SetEncoding(en =>         //数据对应
            {
                en.Y     = Vega.PcField("Horsepower:Q");
                en.Color = cond.ToColor(Color.Gray);
            })
                     .SetSelection(selection);

            var left  = cm.SetEncoding(en => en.X = Vega.PcField("Acceleration:Q"));
            var right = cm.SetEncoding(en => en.X = Vega.PcField("Miles_per_Gallon:Q"));

            //左右2张图
            (left | right).ToFile("res.html");
        }
Пример #6
0
        private static void NewMethod5()
        {
            var url = @"https://vega.github.io/vega-datasets/data/cars.json";

            var selection = Vega.SingleSelection("pts").SetOn("mouseover")
                            .SetNearest(true);


            var cond = Vega.Condition()
                       .AddFiled(Vega.PcField().SetAggregate("count").SetType(FieldType.Quantitative))
                       .AddSelection(selection);


            var cm = Vega.SetData(url)
                     .SetEncoding(en =>
            {
                en.X     = Vega.PcField().SetName("Origin:O");
                en.Y     = Vega.PcField().SetName("Cylinders:O");
                en.Color = cond.ToColor(Color.Gray);
            })
                     .SetSelection(selection);

            var rect = cm.SetMark(Vega.Marks.Rect);

            rect.ToFile("res.html");
        }
Пример #7
0
        private static void test1()
        {
            var url = @"https://vega.github.io/vega-datasets/data/movies.json";

            var selection = Vega.MultiSelection("click")
                            //.SetOn("mousemove{100}")
                            .SetEncodings("x");

            var x = Vega.PcField("IMDB_Rating:Q").SetBin(true);
            var y = Vega.PcField("Rotten_Tomatoes_Rating:Q").SetBin(true);

            var rect = Vega.SetData(url)
                       .SetMark(Vega.Marks.Rect)
                       .SetEncoding(en =>
            {
                en.X     = x;
                en.Y     = y;
                en.Color = Vega.McField()
                           .SetAggregate("count")
                           .SetScale("greenblue")
                           .SetLegend("总数");
            });

            var circ = Vega.SetData(url)
                       .SetMark(Vega.Marks.Point)
                       .SetEncoding(en =>
            {
                en.X     = x;
                en.Y     = y;
                en.Color = Vega.McField().SetColor("grey");
                en.Size  = Vega.McField()
                           .SetAggregate("count")
                           .SetLegend("选中的总数");
            })
                       .SetFilter(selection);


            var bar = Vega.SetData(url)
                      .SetMark(Vega.Marks.Bar)
                      .SetEncoding(en =>
            {
                en.X     = Vega.PcField("Major_Genre:N");
                en.Y     = Vega.PcField().SetAggregate("count");
                en.Color = Vega.Condition().AddSelection(selection).AddValue(Color.SteelBlue)
                           .ToColor(Color.Gray);
            })
                      .SetSelection(selection);

            ((rect + circ) | bar)
            .SetResolveLegend(g =>
            {
                g.Color = ResolveValue.Independent;
                g.Size  = ResolveValue.Independent;
            })
            .ToFile("res.html");
        }
Пример #8
0
        private static void NewMethod4()
        {
            var url = @"https://vega.github.io/vega-datasets/data/stocks.csv";

            var cond = Vega.Condition()
                       .AddTest(d => d.Number("price") > 400)
                       .AddValue(Color.Red);


            var cm = Vega.SetData(url)
                     .SetEncoding(en =>
            {
                en.X     = Vega.PcField().SetName("date:T");
                en.Y     = Vega.PcField().SetName("price:Q");
                en.Color = cond.ToColor(Color.Blue);
            })
                     .SetFilter(d => d.String("symbol") == "GOOG")
            ;

            var line  = cm.SetMark(Vega.Marks.Line);
            var point = cm.SetMark(Vega.Marks.Point);

            (line + point).ToFile("res.html");
        }