Chart not working with UrlAdaptor

I am working with various types of charts. I everything seems to work when I pass a list directly from the controller but when trying to use a UrlAdaptor as the datasource the table never contains any data.

Here is my chart control definition

<ejs-accumulationchart id="container" title="Volunteer Hours" load="window.onChartLoad" enableAnimation="false">
    <e-accumulationchart-tooltipsettings enable="false"></e-accumulationchart-tooltipsettings>
    <e-accumulationchart-legendsettings visible="true"></e-accumulationchart-legendsettings>
    <e-accumulation-series-collection>
        <e-accumulation-series xName="EventType" yName="HoursWorked" name="HoursWorked" query="new ej.data.Query()">
            <e-data-manager crossDomain="true" url="/Home/UrlDatasource" adaptor="UrlAdaptor"></e-data-manager>
        </e-accumulation-series>
    </e-accumulation-series-collection>
</ejs-accumulationchart>

 Here is the definition for the UrlDataAdaptor which correctly returns data.

public JsonResult UrlDatasource([FromBody] DataManagerRequest dm)
{
    IEnumerable<VolunteerHours> DataSource = VolunteerHours.GetAllRecords();
    DataOperations operation = new DataOperations();
    int count = DataSource.Cast<VolunteerHours>().Count();
    if (dm.Where != null && dm.Where.Count > 0) //Filtering
    {
        DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
    }
    if (dm.Skip != 0) //Paging
    {
        DataSource = operation.PerformSkip(DataSource, dm.Skip);
    }
    if (dm.Take != 0)
    {
        DataSource = operation.PerformTake(DataSource, dm.Take);
    }
    return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
}

  I am using VisualStudio 2022, asp.net core v7 and SyncFusion 24.2.3. I have attached a simple example program.


Attachment: SyncfusionWebApplication1_e61489f1.zip

5 Replies

SB Swetha Babu Syncfusion Team February 15, 2024 01:56 AM UTC

Hi Chris,


Greetings from Syncfusion.


We have considered the reported scenario as a bug and logged a defect report for the same. The fix for the reported scenario will be included in our weekly patch release which is expected to be rolled out on 27th February 2024. Please find the below feedback link to keep track of the reported scenario.


Feedback link: https://www.syncfusion.com/feedback/50897/pie-chart-is-not-rendered-when-urladaptor-is-used


Kindly, revert us if you have any concerns.


Regards,

Swetha



SB Swetha Babu Syncfusion Team February 22, 2024 11:04 AM UTC

Chris,


Thank you for your patience.


We can render the chart with url adaptor by adding the DefaultContractResolver in the Startup.cs file to resolve the reported scenario. We have modified the provided sample and the same can be downloaded from the attached file.


Documentation link: https://ej2.syncfusion.com/aspnetcore/documentation/grid/data-binding/data-binding#troubleshoot-grid-render-rows-without-data


Code Snippet:


public void ConfigureServices(IServiceCollection services)

        {

            services.AddControllersWithViews();

            services.AddMvc().AddNewtonsoftJson(options =>

            {

                options.SerializerSettings.ContractResolver = new DefaultContractResolver();

            });

        }


Screenshot:


Image_9046_1708599737448


Kindly, revert us if you have any concerns.



CF Chris Franz February 27, 2024 03:08 PM UTC

Swetha,


  Thank you for this update. I have been able to populate my Charts and Graphs using a URL Adaptor after adding the ContractResolver.

  One additional question can I use a Data Query to specify additional parameters. This is simple to do with DataGrid but I'm not sure how to implement it with a chart and specifically each e-series.  I want to use the same URL Adapter for multiple series. For example monthly counts by year so my query would look something like this.

query="new ej.data.Query().addParams('Year', 2024)"

  Where would this query be included in the chart definition? 

  Alternately could a different URL adapter be specified for each e-series or is it specific to the e-series-collection?






CF Chris Franz February 28, 2024 06:38 PM UTC

Just discovered a few more issues with using the DefaultContractResolver. First off the scheduler control does not render data when the contract resolver is defined. Second it changes the way that parameters are passed back to JAVA in the args.rowData.

For example without the contract resolver parameters come back in camel case with the first letter always in lower case. With the contract resolver defined the exact name of the parameter comes back. So if one of the columns in my data is named EventId with the contract resolver this is parsed to EventId without the contract resolver it becomes eventId.

Not a huge deal but since JAVA is case sensitive this ended up breaking several of my scirpts where I needed to retrieve a value from a row. 


 // Works if contract resolver is not defined
value= args.rowData.eventId 
 // Must be changed to this with contract resolver
 value= args.rowData.EventId 

 I understand that the behavior is different just wanted to point this outAlso any ideas on why the UrlAdapter stopped working with the scheduler let me know.

Chris 



SB Swetha Babu Syncfusion Team March 6, 2024 04:22 AM UTC

Hi Chris,


We have forwarded the query to the corresponding team. So, we will update you with further details once they have replied.


Loader.
Up arrow icon