jQuery UI Widgets Forums ASP .NET MVC Update Chart from Controller

This topic contains 1 reply, has 2 voices, and was last updated by  Hristo 6 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Update Chart from Controller #100296

    vRITHNER
    Participant

    Hi,

    I have a view with a chart and a DropDown control; the first time, the controller send a model with a ChartItem data list to the chart;
    every time I change the selected value from the dropdown control, I want to use the controller to query some new data for the viewmodel.
    now, I struggle to update the chart.
    I tried to use the $(‘#chart’).jqxChart(‘refresh’); but nothing changes.
    The only way I found is kind of heavy
    I had to create a new source in the Javascript to make it work.

    ` var source = {
    datatype: “json”,
    datafields: [
    { name: ‘Day’ },
    { name: ‘SmsCount’ }
    ],
    async: false,
    record: ‘Array’,
    url: ‘@Url.Action(“GetSmsInfoStats”, “Sms”)’+”?monthOffset=”+value
    };`

    it’s working but it’s kind of stupid because the viewmodel contains already the new data and been forced to query the data in another function is sort kind of duplicate way-

    Can you help me to simplify the concept ?
    thanks in advance
    -vince

    Update Chart from Controller #100316

    Hristo
    Participant

    Hello vince,

    You could try to update only the URL of the source – source.url = newurl
    After that just update the DataAdapter with dataAdapter.dataBind() method and set it into the source of the Chart:

    source.url = newurl;
    dataAdapter.dataBind();
    $('#jqxChart').jqxChart({ source: dataAdapter });
    $('#jqxChart').jqxChart('update');
    

    Also, I would like to suggest you look at this article:
    https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxchart/jquery-chart-data-source.htm

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.