Series not using Name Value from Datasource, instead using the field name

I am trying to build a 100% Stacked Column chart using a datamanager.  Everything works except it is not using the field value for my name field, instead it display "nameValue" (that is the name of my field). For now I am adapting your sample with a datasource to use the datamanager, but I will be pulling the values from my database.

Here is my ASP code:

                <ejs-chart id="featureProgressChart" load="window.onChartLoad" title="Gross Domestic Product Growth">

                    <e-chart-primaryxaxis valueType="Category" labelIntersectAction="Rotate45" interval="1">

                        <e-majorgridlines width="0"></e-majorgridlines>

                        <e-minorgridlines width="0"></e-minorgridlines>

                        <e-minorticklines width="0"></e-minorticklines>

                        <e-linestyle width="0"></e-linestyle>

                    </e-chart-primaryxaxis>

                    <e-chart-primaryyaxis rangePadding="None" interval="20" title="GDP (%) per Annum">

                        <e-majorticklines width="0"></e-majorticklines>

                        <e-linestyle width="0"></e-linestyle>

                    </e-chart-primaryyaxis>

                    <e-series-collection>

                        <e-series name="nameValue" xName="xValue" yName="yValue" width="2" opacity="1" type="@Syncfusion.EJ2.Charts.ChartSeriesType.StackingColumn100">

                            <e-data-manager url="/ProductArea/FeatureProgressChartData"

                                    adaptor="UrlAdaptor">

                            </e-data-manager>

                        </e-series>

                    </e-series-collection>

                    <e-chart-tooltipsettings enable="true" format="${point.x} : <b>${point.y} (${point.percentage}%)</b>"></e-chart-tooltipsettings>

                    <e-chart-chartarea>

                        <e-chartarea-border width="0"></e-chartarea-border>

                    </e-chart-chartarea>

                </ejs-chart>


Here is my controller code:


            List<FeatureProgressChartData> chartList = new List<FeatureProgressChartData>();


            FeatureProgressChartData itemToAdd1 = new FeatureProgressChartData()

            {

                nameValue = "UK",

                xValue="2014",

                yValue=111

            };

            chartList.Add(itemToAdd1);


            FeatureProgressChartData itemToAdd10 = new FeatureProgressChartData()

            {

                nameValue = "UK",

                xValue = "2015",

                yValue = 127

            };

            chartList.Add(itemToAdd10);


            FeatureProgressChartData itemToAdd11 = new FeatureProgressChartData()

            {

                nameValue = "UK",

                xValue = "2016",

                yValue = 143

            };

            chartList.Add(itemToAdd11);


            FeatureProgressChartData itemToAdd12 = new FeatureProgressChartData()

            {

                nameValue = "UK",

                xValue = "2017",

                yValue = 159

            };

            chartList.Add(itemToAdd12);


       FeatureProgressChartData itemToAdd2 = new FeatureProgressChartData()

            {

                nameValue = "Germany",

                xValue = "2014",

                yValue = 76

            };

            chartList.Add(itemToAdd2);


            FeatureProgressChartData itemToAdd20 = new FeatureProgressChartData()

            {

                nameValue = "Germany",

                xValue = "2015",

                yValue = 99

            };

            chartList.Add(itemToAdd20);


            FeatureProgressChartData itemToAdd21 = new FeatureProgressChartData()

            {

                nameValue = "Germany",

                xValue = "2016",

                yValue = 121

            };

            chartList.Add(itemToAdd21);


            FeatureProgressChartData itemToAdd22 = new FeatureProgressChartData()

            {

                nameValue = "Germany",

                xValue = "2017",

                yValue = 142

            };

            chartList.Add(itemToAdd22);


            FeatureProgressChartData itemToAdd3 = new FeatureProgressChartData()

            {

                nameValue = "Italy",

                xValue = "2014",

                yValue = 66

            };

            chartList.Add(itemToAdd3);


            FeatureProgressChartData itemToAdd30 = new FeatureProgressChartData()

            {

                nameValue = "Italy",

                xValue = "2015",

                yValue = 79

            };

            chartList.Add(itemToAdd30);


            FeatureProgressChartData itemToAdd31 = new FeatureProgressChartData()

            {

                nameValue = "Italy",

                xValue = "2016",

                yValue = 91

            };

            chartList.Add(itemToAdd31);


            FeatureProgressChartData itemToAdd32 = new FeatureProgressChartData()

            {

                nameValue = "Italy",

                xValue = "2017",

                yValue = 102

            };

            chartList.Add(itemToAdd32);


            return Json(new { result = chartList, count = chartList.Count });

        }


    public class FeatureProgressChartData

    {

        public string nameValue { get; set; }

        public string xValue { get; set; }

        public int yValue { get; set; }

    }

Thanks

- Ken


5 Replies

SB Swetha Babu Syncfusion Team July 13, 2022 10:52 AM UTC

Hi Ken,


Greetings from Syncfusion.


We can change the legend name by using the text argument in legendRender event in Charts. However, we have created a simple Core application by using the provided code snippet and it will be helpful for us to analyze further and assist you better.


Sample link:  https://www.syncfusion.com/downloads/support/directtrac/general/ze/ChartSample-1982448654


Code Snippet:


<ejs-chart id="featureProgressChart" legendRender=" legend" title="Gross Domestic Product Growth"></ejs-chart>

 

<script>

    window.legend = function (args) {

        args.text = "UK";

    }

</script>


Screenshot:



Kindly, revert us if you have any concerns.


Regards,

Swetha



KK Ken Kitts July 13, 2022 01:35 PM UTC

Thanks for your reply.  I may not have been clear in my question.  Here is what I am trying to accomplish:


I will dynamically be creating charts based on the Product Area that is being viewed (each Product Area contains multiple Features).  This chart will summarize the progress of each feature.  My goal is to create something like this (this sample chart is done in Excel):


The legend and stacked columns will all come from the database, so I can't hard code them like your sample, this is why I am using a Datamanager instead of ViewBag like your example shows.

I have taken your existing sample using ViewBag and successfully can get it to create the following chart:


Then I tried to recreate the same chart using a datamanger instead of the viewbag (similiar to what I need in my solution), hoping to get the same chart (this is the code in my original post).  Instead I get the error described above, where I get "nameValue" instead of the value of the nameValue field - all other data on the chart is populating correcctly.  Here is this chart:


Thanks for your help.

- Ken













DG Durga Gopalakrishnan Syncfusion Team July 18, 2022 12:50 PM UTC

Hi Ken,

 

We suggest you to specify the name for each series as separate string instead of specifying in datasource and you can access that property using foreach inside series collection. We have prepared sample based on your requirement. 

 

<ejs-chart id="container">       <e-series-collection>

          @foreach (var item in ViewBag.seriesCollection)

         {

             <e-series dataSource="@item.Data" name="@item.Name" xName="x" width="2" yName="y" width="2" opacity="1" type="@Syncfusion.EJ2.Charts.ChartSeriesType.StackingColumn">

             </e-series>

         }

     </e-series-collection></ejs-chart> public IActionResult Index()

        {

            List<SeriesData> series = new List<SeriesData>();

            series.Add(new SeriesData

            {

                Name = "UK",

                Data = new List<StackedColumnChartData>

                {

                        new StackedColumnChartData { x= "2014", y= 111.1 },

                        new StackedColumnChartData { x= "2015", y= 127.3 }

                       //...

                }

            });          //....          ViewBag.seriesCollection = series;

          return View();

        }



 

Kindly revert us if you have any concerns.

 

Regards,

Durga Gopalakrishnan.


Attachment: StckColumn_7a585c0d.zip


KK Ken Kitts July 18, 2022 12:58 PM UTC

Thanks for your reply.  As I have said hard coding them is NOT an option, they have to be driven from the database (this doesn't seem like that unusual of a request).

Based on your response, I will assume that your control is not able to do that and will look for another option.


Thanks

- Ken



DG Durga Gopalakrishnan Syncfusion Team July 19, 2022 02:46 PM UTC

Hi Ken,


We don’t have mapping support for chart series name. Since, it is a string, you can specify the require value for name property. Datasource is an array of object which includes x and y values that can be mapped in chart series using xName and yName property.


If you are specifying the name inside datasource, you can access its value in chart load event and assign it to chart series name as like below snippet.


<ejs-chart load="onChartLoad"></ejs-chart>

<script>

    function onChartLoad(args){

        args.chart.series[0].name = args.chart.series[0].dataSource[0].nameValue;

    }

</script>


Please let us know if you have any concerns.


Regards,

Durga Gopalakrishnan.


Loader.
Up arrow icon