-1

how to visualize a dataframe in a NOT NOTEBOOK APP (in a console application e.g.)

using a library like XPlot.Plotly in a console application

var data = Enumerable.Range(0, 100).Select(v => v + .0);
Chart.Bar(data).Show();

it opens the browser automatically and shows me a chart.

But, how if i want to visualize the entire dataframe in tabular format?

i've tried to configure a Formatter but how to visualize?

Formatter.Register<DataFrame>((df, writer) =>
{
    var headers = new List<IHtmlContent>();
    headers.Add(th(i("index")));
    headers.AddRange(df.Columns.Select(c => (IHtmlContent)th(c.Name)));
    var rows = new List<List<IHtmlContent>>();
    var take = 20;
    for (var i = 0; i < Math.Min(take, df.Rows.Count); i++)
    {
        var cells = new List<IHtmlContent>();
        cells.Add(td(i));
        foreach (var obj in df.Rows[i])
        {
            cells.Add(td(obj));
        }
        rows.Add(cells);
    }

    var t = table(
        thead(
            headers),
        tbody(
            rows.Select(
                r => tr(r))));

    writer.Write(t);
}, "text/html");

It seems to work in a notebook only, how can "to pass" this formatter to XPlot (or another library) in order to open the browser and show it ( like Chart.Bar(data).Show(); does?

pinale
  • 2,060
  • 6
  • 38
  • 72
  • 1
    Have you tried creating a [Google Table chart](https://fslab.org/XPlot//chart/google-table-chart.html)? The code you posted creates HTML anyway. You don't need XPlot for that at all. `Show()` doesn't do any magic either, it [saves the generated HTML to a temp file and opens it with a browser](https://github.com/fslaborg/XPlot/blob/main/src/XPlot.Plotly/Main.fs#L41) – Panagiotis Kanavos Aug 25 '23 at 08:57
  • Is it possible customize the layout of google table chart in order color cells conditionally? (e.g. heatmap) – pinale Aug 25 '23 at 11:09
  • end eventually my code `Formatter.Register` where does it put the html? if i woluld get this html content i'd try to do the same the method `show()` does – pinale Aug 25 '23 at 17:18
  • 1
    Nowhere. You're creating a new type of plot, not formatting an existing one. Did you try the Table chart yet? As for `the same the method show does` I already linked to the *actual line* that calls `Process.Start(that.html)`. The *Plot*, in this case Table or Bar generates the HTML and *Show* saves it to disk and opens it – Panagiotis Kanavos Aug 25 '23 at 17:27
  • i can't (i'm not able) to use `XPlot.GoogleCharts.Chart.Table` because this object has a **sign** that i can't translate from f# to c#. `XPlot.GoogleCharts.Chart.Table(IEnumerable> data, .....` whereas i'm trying to pass the entire dataframe to the table method `XPlot.GoogleCharts.Chart.Table(df)` obviously isn't correct, so should i extract this `IEnumerable` from the dataframe and pass it to the method? i didn't found any example of this in c#, incredible – pinale Aug 25 '23 at 17:41

0 Answers0