Posted 22 August 2021, 11:19 pm EST
Is there a way to create a click action on the items in the treemap component.Best Regards
Emil
Forums Home / ComponentOne / Blazor Edition Topics
Posted by: ehh on 22 August 2021, 11:19 pm EST
Posted 22 August 2021, 11:19 pm EST
Is there a way to create a click action on the items in the treemap component.Replied 24 August 2021, 3:31 pm EST
Hi,<TreeMap @ref="map" Class="chart" ItemsSource="Data" Binding="Sales" BindingName="Category" ChildItemsPath="Items" Tooltip="{value}" SelectionMode="ChartSelectionMode.Point" >
<Label>
<DataLabel Content="{name}" />
</Label>
</TreeMap>
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
map.SelectionChanged += SelectionChanged;
}
}
protected void SelectionChanged (object sender, EventArgs args)
{
TreeMap _map = (TreeMap)sender;
//param.Context = "D";
}
Replied 26 August 2021, 5:26 pm EST
Hello Manish,@using C1.Chart;
@using C1.DataCollection;
@using C1.Blazor.Chart;
@using C1.Blazor.Input;
<TreeMap @ref="map" Class="c1height" ItemsSource="Data" Binding="Amount" BindingName="Cat" SelectionMode="ChartSelectionMode.Point" ChildItemsPath="Items" Style="@("height:100%;max-height:100%;")"
Tooltip="{value:N0}" Palette="Palette.Custom" CustomPalette="GeneralConstants.CustomPalette" LegendPosition="Position.None">
<Label>
<DataLabel Position="LabelPosition.Center" Content="{name}" />
</Label>
</TreeMap>
@code {
[Parameter]
public Tile Tile { get; set; }
[Parameter]
public TileData TileData { get; set; }
TreeMap map;
List<TreeMapItem> Data { get; set; }
protected override async Task OnInitializedAsync()
{
Data = TreeMapItem.GetData(TileData);
}
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
map.SelectionChanged += SelectionChanged;
}
}
protected void SelectionChanged(object sender, EventArgs args)
{
TreeMap _map = (TreeMap)sender;
//param.Context = "D";
}
class TreeMapItem
{
public string Cat { get; set; }
public double Amount { get; set; }
public List<TreeMapItem> Items { get; set; }
public static List<TreeMapItem> GetData(TileData tileData)
{
var data = new List<TreeMapItem>();
TreeMapItem item = new TreeMapItem();
for (int i = tileData.Columns; i < tileData.Cells.Count() - tileData.Columns; i++)
{
if (i == tileData.Columns)
{
item = new TreeMapItem { Cat = tileData.Cells.ElementAt(i).V.ToString(), Items = new List<TreeMapItem>() };
item.Items.Add(new TreeMapItem { Cat = tileData.Cells.ElementAt(++i).V.ToString(), Amount = Convert.ToDouble(tileData.Cells.ElementAt(++i).V) });
}
else
{
if (item.Cat != tileData.Cells.ElementAt(i).V.ToString())
{
data.Add(item);
item = new TreeMapItem { Cat = tileData.Cells.ElementAt(i).V.ToString(), Items = new List<TreeMapItem>() };
item.Items.Add(new TreeMapItem { Cat = tileData.Cells.ElementAt(++i).V.ToString(), Amount = Convert.ToDouble(tileData.Cells.ElementAt(++i).V) });
}
else
{
item.Items.Add(new TreeMapItem { Cat = tileData.Cells.ElementAt(++i).V.ToString(), Amount = Convert.ToDouble(tileData.Cells.ElementAt(++i).V) });
}
}
}
data.Add(item);
return data;
}
}
Replied 26 August 2021, 7:57 pm EST
Hi,Replied 26 August 2021, 10:10 pm EST
Hi,Replied 30 August 2021, 4:47 pm EST
Hi,Replied 30 August 2021, 5:38 pm EST
Hello Ashwin,Replied 31 August 2021, 7:13 pm EST
Hi,Replied 31 August 2021, 10:20 pm EST
Hello Dushyant,Replied 1 September 2021, 9:24 pm EST
Hi,Replied 19 February 2022, 7:00 pm EST
Hi,