I want to generate an interactive chart, which will dynamical change base on a mutilselector of category
@code{
public class Sales{
public string StoreID;
public double FoodSales;
public double DrinkSales;
public double OtherSales;
public DateTime Month;
}
}
The mutliselector will provide a list of StoreID, and the page will render a stacked area chart based on the store list.
The thing is, if I use a local datasource, the query works fine,
<ChartSeries DataSource=@salesList Query=@QueryData Name="Food" XName="Month" YName="Food" Type="ChartSeriesType.StackingArea">
@code{
public string QueryData = "new ej.data.Query().where('StoreID','equal','0001')";
}
but if I use a client side datamanager, it won't work.
<EjsDataManager Url="http://localhost:3000/saleList" Adaptor="Adaptors.WebApiAdaptor" Offline="true" ></EjsDataManager>
<ChartSeries Query=@QueryData Name="Food" XName="Month" YName="Food" Type="ChartSeriesType.StackingArea">
My understanding is that the chart can only take the response with format of { "result":[{}{}...{}],"count":6} and bind it, which might prevent it from execute a client side query, while the grid can take response of [{}{}{}...{}] format and do some local fitlering.
My question is, is there a way to work around or would it be a new feature you guys might consider?
|
<EjsChart id="container1">
<EjsDataManager Url="https://mvc.syncfusion.com/Services/Northwnd.svc/Tasks/" CrossDomain="true"></EjsDataManager>
<ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries Type="ChartSeriesType.Column" xName="Assignee" yName="Estimate" Query=@QueryData>
</ChartSeries>
</ChartSeriesCollection>
</EjsChart>
@code{
public string QueryData = "new ej.data.Query().take(5).where('Estimate', 'lessThan', 3, false)";
} |
|
<EjsChart id="container1">
<EjsDataManager Url="https://mvc.syncfusion.com/Services/Northwnd.svc/Tasks/" Offline="true"></EjsDataManager>
<ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries Type="ChartSeriesType.Column" xName="Assignee" yName="Estimate" Query=@QueryData>
</ChartSeries>
</ChartSeriesCollection>
</EjsChart>
@code{
public string QueryData = "new ej.data.Query().take(5).where('Estimate', 'lessThan', 3, false)";
} |
|
<EjsDataManager @ref="DataManager" Url="https://mvc.syncfusion.com/Services/Northwnd.svc/Tasks/"></EjsDataManager>
<EjsChart DataSource="DataSource" id="container1">
<ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries Type="ChartSeriesType.Column" XName="Assignee" YName="Estimate" Query="@QueryData">
</ChartSeries>
</ChartSeriesCollection>
</EjsChart>
<EjsButton OnClick="@ChangeQuery">Change Query</EjsButton>
@code{
EjsDataManager DataManager;
public IEnumerable<Order> DataSource { get; set; } = new List<Order>();
public ChartSeries DefaultChartSeries = new ChartSeries();
public string QueryData = "new ej.data.Query().take(5).where('Estimate', 'lessThan', 1.5, false)";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{ //provide generic type TValue
object data = await DataManager.ExecuteQuery<Order>(new Query());
DataSource = (data as IEnumerable).Cast<Order>().ToList();
StateHasChanged();
}
}
public class Order
{
public int? Id { get; set; }
. . . . .
}
} |
How can I run a client-side query directly on a chart without using a backend API?
Is there a way to dynamically filter or update chart data in real time on the client side?
What’s the best method to bind client-side queries to meal cost at chick fil-a interactive chart components?
Joy,
You can dynamically filter or update chart data on the client side by modifying the bound data collection and calling StateHasChanged() or chart RefreshAsync() to reflect changes. You can use LINQ queries on the local data source to filter or transform data and bind the chart data as List or ObservableCollection. This approach avoids backend API calls and keeps everything client-side.
We have prepared a sample that demonstrates client-side filtering using a dropdown. It dynamically updates the chart without any backend API calls by modifying the data source and calling StateHasChanged().
|
private void OnFilterChange(ChangeEventArgs args) { var selected = args.Value.ToString();
if (selected == "High") { FilteredData = AllData.Where(d => d.Value > 50).ToList(); } else if (selected == "Low") { FilteredData = AllData.Where(d => d.Value <= 50).ToList(); } else { FilteredData = AllData; }
StateHasChanged(); } |
Sample : https://blazorplayground.syncfusion.com/BtLIiMCMICoZgUUP
If the provided suggestion doesn’t meet your requirement, please share your requirement in detail so that it will be helpful for us to analyze further and assist you better. Please let us know if you have any concerns.