如何使用c#Bot Framework创建图表? [英] How to create Charts using c# Bot Framework?

查看:110
本文介绍了如何使用c#Bot Framework创建图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在漫游器中创建一些图表(折线图等).我可以从在线来源(finance.Yahoo.com)上获得数据

I am trying to create some charts(line graph etc.,) in a bot. I have the data available from an online source (finance.Yahoo.com)

我不确定为此应使用哪个库
1.什么图表库?
2.我应该使用哪种类型的卡(英雄卡,自适应卡...)?
3.我当前连接到外部网站(Yahoo)的解决方案是Web api,我正在使用C#机器人框架?

I am not sure what library I should be using for this purpose
1. What chart library?
2. What type of Card (Hero Card, Adaptive Card ...) should I use?
3. My current solution which is connecting to external site (Yahoo) is a web api and I am using C# bot framework?

任何人都可以分享一个有关如何实现这一目标的例子吗?

Could anyone share an example on how can I achieve this?

我尝试使用UI.Visualization.Chart库,但未成功获得解决方案.因此,我正在这方面寻求帮助

I have tried to use UI.Visualization.Chart library but I wasn't successful in getting the solution. Hence I am looking for some help in this area

推荐答案

BotFramework当前不支持交互式图表,您可以使用@Peter Bons建议的一些第三方库或在线服务来生成图表,但是您将需要尝试将其渲染为图像文件,并使用bot中的HeroCard/AdaptiveCard将此文件附加到您的消息中.

Interactive charts are not currently supported in BotFramework, you can use some third-party libs as @Peter Bons suggested or on-line services to generate your chart, but you will need to try to render it as an image file and attach this file to your message using HeroCard/ AdaptiveCard in bot.

由于您的数据在Finance.Yahoo.com中,因此我不确定Yahoo是否支持生成图表图像,否则,您将需要从Yahoo获取数据,然后尝试查找在线服务或第三方-party lib首先绘制图表图像.

Since your data is in finance.Yahoo.com, I'm not sure if Yahoo supports to generate chart image, if not, you will need to get the data from Yahoo and then try to find an online-service or third-party lib to draw the chart image first.

渲染图像后,可以将其作为图像附件发送 例如这样的

After the image is rendered, you can send it as image attachment for example like this:

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);

        return Task.CompletedTask;
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var activity = await result as Activity;

        var card = CreateHeroCard();
        Attachment attachment = card.ToAttachment();
        var message = context.MakeMessage();
        message.Attachments.Add(attachment);

        await context.PostAsync(message);

        context.Wait(MessageReceivedAsync);
    }

    private HeroCard CreateHeroCard()
    {
        List<CardImage> cardImages = new List<CardImage>();
        cardImages.Add(new CardImage("your chart image url goes here"));
        var card = new HeroCard()
        {
            Title = "Months with Numbers Bar Chart",
            Subtitle = "Using a Chart as Image service...",
            Text = "Build and connect intelligent bots that have charts rendered as images.",
            Images = cardImages
        };

        return card;
    }
}

这篇关于如何使用c#Bot Framework创建图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆