We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

SeriesType

Hi,

I want to soft code the "SeriesType.Bar" of javascript code to paint the bar chart.
I want to assign value to ".Series(sr =>.Type())" from controller using viewbag.

How I can typecast a string value to SeriesType. something to plot either a "Column" or "bar" chart.

Thanks.






1 Reply

JA Jayavigneshwaran Syncfusion Team January 14, 2015 09:06 AM UTC

Hi Kalpa,

Thanks for using Syncfusion product.

We have analyzed this. This can be done by following the below steps.

1.       Pass the type of the chart to be rendered in controller through viewbag.

[CS]

        public ActionResult ChartFeatures()

        {

            ViewBag.type = "spline"; // passed the chart series type

            return View();

  }

2.       Trigger load event of chart

[CSHTML]

     @(Html.EJ().Chart("container")

      

            .Load("onchartload")

       

     )

3.       Covert the value from viewbag to use it in JS

[JS]

   var seriesType = @Html.Raw(Json.Encode(ViewBag.type)); // Converts the value to use it in JS

4.       Code the method, to assign the value passed in viewbag to chart on load

[JS]

                     function  onchartload(sender) {

            sender.model.series[0].type = seriesType; // assign it to chart seriestype

        }

The below screen shot shows the output of the attached sample.

We have also made a sample to illustrate this. Find it from the below location.

 Attachment.zip

Please let us know if you have any concern.

Thanks,

Jayavigneshwaran



Loader.
Live Chat Icon For mobile
Up arrow icon