Chart Data

Performance !!!

Bar and Column Charts

Line and Area Charts

Pie and Funnel Charts

Scatter and Bubble Charts

Radar and Polar Charts

Financial Charts

Gantt Charts

Combinational Charts

Dynamic Charts

Working with Chart Axes

Chart Features

Customizing Chart

Client-Side Events




This sample demonstrates how to change (add, remove) chart data points.

To change the chart data, you can just change the data array and call the .jqChart("update") method. The jqChart will handle the rest.

For detailed implementation, please take a look at the Aspx, Razor and Controller code tabs.
 
<%@ Page  Language="C#"  Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="JQChart.Web.Mvc" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>    
    <link rel="stylesheet" type="text/css" href="~/Content/jquery.jqChart.css" />
    <link rel="stylesheet" type="text/css" href="~/Content/themes/le-frog/jquery-ui-1.8.20.css" />
    <script src="<%: Url.Content("~/Scripts/jquery-1.11.1.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/jquery.jqChart.min.js") %>" type="text/javascript"></script>    
	<body>
    <%= Html.JQChart()
            .Chart()
            .ID("jqChart")
            .Width(500)
            .Height(300)
            .Title("Change Data Points")
            .Border(border => border.StrokeStyle("#6ba851"))
            .Background(background => background.LinearGradient(0, 0, 0, 1).ColorStops(stop =>
            {
                stop.Add(0, "#d2e6c9");
                stop.Add(1, "white");
            }))
            .Series(series =>
                {
                    series.Column().Title("Column")
                                   .YValues(new double[] { 20, 50, 40, 60, 70 })
                                   .FillStyle(background => background.LinearGradient(0, 0, 1, 0).ColorStops(stop =>
                                   {
                                       stop.Add(0, "#65c2e8");
                                       stop.Add(0.49, "#55b3e1");
                                       stop.Add(0.5, "#3ba6dc");
                                       stop.Add(1, "#2794d4");
                                   }));
                }
            )
            .Render()%>
    <br />
    <input id="buttonAddPoint" type="button" value="Add new point" />
    <input id="buttonRemovePoint" type="button" value="Remove last point" />
    <br />
    <script lang="javascript" type="text/javascript">
        $(document).ready(function () {

            $('#buttonAddPoint').click(function () {

                // get current series
                var series = $('#jqChart').jqChart('option', 'series');

                // get the data from the first series
                var data = series[0].data;

                // add new data item
                data.push(Math.round(Math.random() * 100));

                // update (redraw) the chart
                $('#jqChart').jqChart('update');
            });

            $('#buttonRemovePoint').click(function () {

                // get current series
                var series = $('#jqChart').jqChart('option', 'series');

                // get the data from the first series
                var data = series[0].data;

                // remove the last data item
                data.splice(data.length - 1, 1);

                // update (redraw) the chart
                $('#jqChart').jqChart('update');
            });
        });
    </script>
</body>
</html>

                                        
 

@using JQChart.Web.Mvc

<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>    
    <link rel="stylesheet" type="text/css" href="~/Content/jquery.jqChart.css" />
    <link rel="stylesheet" type="text/css" href="~/Content/themes/le-frog/jquery-ui-1.8.20.css" />
    <script src="@Url.Content("~/Scripts/jquery-1.11.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.jqChart.min.js")" type="text/javascript"></script>    
	<body>
      @(Html.JQChart()
            .Chart()
            .ID("jqChart")
            .Width(500)
            .Height(300)
            .Title("Change Data Points")
            .Border(border => border.StrokeStyle("#6ba851"))
            .Background(background => background.LinearGradient(0, 0, 0, 1).ColorStops(stop =>
            {
                stop.Add(0, "#d2e6c9");
                stop.Add(1, "white");
            }))
            .Series(series =>
                {
                    series.Column().Title("Column")
                                   .YValues(new double[] { 20, 50, 40, 60, 70 })
                                   .FillStyle(background => background.LinearGradient(0, 0, 1, 0).ColorStops(stop =>
                                   {
                                       stop.Add(0, "#65c2e8");
                                       stop.Add(0.49, "#55b3e1");
                                       stop.Add(0.5, "#3ba6dc");
                                       stop.Add(1, "#2794d4");
                                   }));
                }
            )
            .Render() 
          )
    <br />
    <input id="buttonAddPoint" type="button" value="Add new point" />
    <input id="buttonRemovePoint" type="button" value="Remove last point" />
    <br />
    <script lang="javascript" type="text/javascript">
        $(document).ready(function () {

            $('#buttonAddPoint').click(function () {

                // get current series
                var series = $('#jqChart').jqChart('option', 'series');

                // get the data from the first series
                var data = series[0].data;

                // add new data item
                data.push(Math.round(Math.random() * 100));

                // update (redraw) the chart
                $('#jqChart').jqChart('update');
            });

            $('#buttonRemovePoint').click(function () {

                // get current series
                var series = $('#jqChart').jqChart('option', 'series');

                // get the data from the first series
                var data = series[0].data;

                // remove the last data item
                data.splice(data.length - 1, 1);

                // update (redraw) the chart
                $('#jqChart').jqChart('update');
            });
        });
    </script>
</body>
</html>

                                        
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SamplesBrowser.Models
{
    public class EmptyChartModel
    { 
    }
}
                                        
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SamplesBrowser.Models;

namespace SamplesBrowser.Controllers
{
    public class ChartController : Controller
    {

        public ActionResult ChartDataPoints() 
        { 
            return View(); 
        }

    }
}