apexcharts / Blazor-ApexCharts

A blazor wrapper for ApexCharts.js
https://apexcharts.github.io/Blazor-ApexCharts
MIT License
788 stars 91 forks source link

Object with Dictionary property #386

Closed mcash95 closed 7 months ago

mcash95 commented 7 months ago

i have an object im working with that contains a dictionary<int,int> property. how would i go about adding a list of these objects but graphing the dictionary property.

ex

`

`

Im using the blazor wrapper for reference.

Thank you in advance!

joadan commented 7 months ago

Hello,

Not sure the best way to do it, but one way is to create your own type.

<DemoContainer>

    <ApexChart TItem="ChartData"
               Title="Basic Sample">

        <ApexPointSeries Items="data"
                         SeriesType="@SeriesType.Area"
                         Name="Gross Value"
                         XValue="@(e => e.XValue)"
                         YValue="@(e => e.YValue)" />
    </ApexChart>

</DemoContainer>

@code {
    List<ChartData> data;
    protected override void OnInitialized()
    {
        var dic = new Dictionary<int, int>();
        dic.Add(1, 44);
        dic.Add(2, 12);
        dic.Add(3, 5);
        dic.Add(4, 66);

        data = dic.Select(e => new ChartData { XValue = e.Key, YValue = e.Value }).ToList();
    }

    class ChartData
    {
        public int XValue { get; set; }
        public int YValue { get; set; }
    }

}