【问题标题】:Linqpad extension to plot graphs用于绘制图形的 Linqpad 扩展
【发布时间】:2017-01-03 15:04:25
【问题描述】:

我尝试使用“Util.RawHtml()”和“Dump()”在 Linqpad 中绘制一些图表,但它不适用于来自 amcharts.com 的 example。我创建了一个包含所有 HTML 源代码的字符串变量,但结果不起作用。

string html = "";
using (System.Net.WebClient client = new System.Net.WebClient ())
{
    html = client.DownloadString(@"http://pastebin.com/raw/pmMMwXhm");
}

Util.RawHtml(html).Dump();

【问题讨论】:

  • 不幸的是,Util.RawHtml 对其允许的内容进行了 非常 强验证,因此它可能实际上不接受 html,即使它可能对浏览器有效。您是否可以生成图像?另外,请务必解释“不工作”的含义。你有任何结果吗?例外?碰撞?输出错误?

标签: linqpad


【解决方案1】:

LinqPad 5 的最新版本现在支持使用 Util.Chart 开箱即用地绘制图表。您可以在

下的Samples 选项卡(My Queries 旁边)中查看示例
  • LINQPad Tutorial&Reference
    • Scratchpad Features
      • Charting with Chart

下面的脚本是Chart() - dual scale sample:

// Each y-series can have a different series type, and can be assigned to the secondary y-axis scale on the right.

var customers = new[]
{
    new { Name = "John", TotalOrders = 1000, PendingOrders = 50, CanceledOrders = 20 },
    new { Name = "Mary", TotalOrders = 1300, PendingOrders = 70, CanceledOrders = 25 },
    new { Name = "Sara", TotalOrders = 1400, PendingOrders = 60, CanceledOrders = 17 },
};

customers.Chart (c => c.Name)
    .AddYSeries (c => c.TotalOrders,    Util.SeriesType.Spline, "Total")
    .AddYSeries (c => c.PendingOrders,  Util.SeriesType.Column, "Pending",   useSecondaryYAxis:true)
    .AddYSeries (c => c.CanceledOrders, Util.SeriesType.Column, "Cancelled", useSecondaryYAxis:true)
    .Dump();

【讨论】:

    【解决方案2】:

    据我了解,这不起作用,因为 html 包含不会执行的脚本。

    作为替代方案,您仍然可以使用旧的(已弃用的)谷歌图表 api,例如

    var link = @"http://chart.apis.google.com/chart?chxt=y&chbh=a&chs=300x225&cht=bvg&chco=A2C180,3D7930&chd=t:10,20,30,40,50,60|30,35,40,45,55,60&chtt=Sample";
    
    Util.Image (link).Dump();
    

    或见 http://blog.divebomb.org/2012/11/dumping-charts-in-linqpad/

    【讨论】:

      【解决方案3】:

      不确定这是否是您想要的答案,但查看 Linqpad 中 Util 类上的 DisplayWebPage 方法可能很有价值。这在结果窗口中正确呈现了您的图表(尽管存在脚本错误)。显然,这可能无法解决您的根本问题。

      我使用了 5.10.00 版本来测试这个。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-03
        • 1970-01-01
        • 2011-05-09
        • 2019-03-04
        • 1970-01-01
        • 2011-07-03
        • 1970-01-01
        相关资源
        最近更新 更多