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 series.

To change the chart series, you can just change the series 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<IEnumerable<SamplesBrowser.Models.ScatterChartData>>" %>

<%@ 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(Model)
            .ID("jqChart")
            .Width(500)
            .Height(300)
            .Title("Change Series")
            .Legend(false)
            .Border(border => border.StrokeStyle("#6ba851"))
            .Background(background => background.LinearGradient(0, 0, 0, 1).ColorStops(stop =>
            {
                stop.Add(0, "#d2e6c9");
                stop.Add(1, "white");
            }))
            .Axes(axis =>
                {
                    axis.LinearAxis(Location.Bottom)
                        .Minimum(0)
                        .Maximum(20);

                    axis.LinearAxis(Location.Left)
                        .Minimum(0)
                        .Maximum(100);
                }
             )
            .Series(series =>
                {
                    series.Line().XValues(el => el.ValueX)
                                 .YValues(el => el.ValueY1);
                }
            )
            .Render()%>
    <br />
    <input id="buttonAddSeries" type="button" value="Add new series" />
    <input id="buttonRemoveSeries" type="button" value="Remove last series" />
    <br />
    <script lang="javascript" type="text/javascript">
        $(document).ready(function () {

            function getRandomData() {
                var data = [];

                for (var i = 0; i < 20; i++) {
                    data.push([i, Math.round(Math.random() * 100)]);
                }

                return data;
            }

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

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

                var newSeries = {
                    type: 'line',
                    data: getRandomData()
                };

                // get the data from the first series
                series.push(newSeries);


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

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

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

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

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

                                        
 
@model IEnumerable<SamplesBrowser.Models.ScatterChartData>
@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(Model)
            .ID("jqChart")
            .Width(500)
            .Height(300)
            .Title("Change Series")
            .Legend(false)
            .Border(border => border.StrokeStyle("#6ba851"))
            .Background(background => background.LinearGradient(0, 0, 0, 1).ColorStops(stop =>
            {
                stop.Add(0, "#d2e6c9");
                stop.Add(1, "white");
            }))
            .Axes(axis =>
                {
                    axis.LinearAxis(Location.Bottom)
                        .Minimum(0)
                        .Maximum(20);

                    axis.LinearAxis(Location.Left)
                        .Minimum(0)
                        .Maximum(100);
                }
             )
            .Series(series =>
                {
                    series.Line().XValues(el => el.ValueX)
                                 .YValues(el => el.ValueY1);
                }
            )
            .Render() 
          )
    <br />
    <input id="buttonAddSeries" type="button" value="Add new series" />
    <input id="buttonRemoveSeries" type="button" value="Remove last series" />
    <br />
    <script lang="javascript" type="text/javascript">
        $(document).ready(function () {

            function getRandomData() {
                var data = [];

                for (var i = 0; i < 20; i++) {
                    data.push([i, Math.round(Math.random() * 100)]);
                }

                return data;
            }

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

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

                var newSeries = {
                    type: 'line',
                    data: getRandomData()
                };

                // get the data from the first series
                series.push(newSeries);


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

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

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

                // remove the last series
                series.splice(series.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 ScatterChartData
    {
        public static List<ScatterChartData> GetRandom()
        {
            var data = new List<ScatterChartData>();

            Random rnd = new Random();

            for (var i = 0; i < 20; i++)
            {
                data.Add(new ScatterChartData(i, rnd.Next(0, 100)));
            }

            return data;
        }

        public static List<ScatterChartData> GetData()
        {
            var data = new List<ScatterChartData>();

            Random rnd = new Random();

            int yValue1 = 100;
            int yValue2 = 20;

            for (var i = 0; i < 20; i++)
            {
                yValue1 += (int)Math.Round(rnd.NextDouble() * 20 - 10);
                yValue2 += (int)Math.Round(rnd.NextDouble() * 20 - 10);

                data.Add(new ScatterChartData(i, yValue1, yValue2));
            }

            return data;
        }

        public static List<ScatterChartData> GetSplineScatterSampleData()
        {
            var data = new List<ScatterChartData>();

            data.Add(new ScatterChartData(1, 46, 69));
            data.Add(new ScatterChartData(2, 48, 57));
            data.Add(new ScatterChartData(3, 68, 86));
            data.Add(new ScatterChartData(4, 30, 70));
            data.Add(new ScatterChartData(5, 55, 70));
            data.Add(new ScatterChartData(6, 85, 60));
            data.Add(new ScatterChartData(7, 43, 88));
            data.Add(new ScatterChartData(8, 29, 60));

            return data;
        }

        public ScatterChartData(double valueX, double valueY)
        {
            this.ValueX = valueX;
            this.ValueY1 = valueY;
        }

        public ScatterChartData(double valueX, double valueY1, double valueY2)
        {
            this.ValueX = valueX;
            this.ValueY1 = valueY1;
            this.ValueY2 = valueY2;
        }

        public double ValueX { get; set; }
        public double ValueY1 { get; set; }
        public double ValueY2 { get; set; }
    }
}
                                        
 
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 ChartSeries()
        {
            return View(ScatterChartData.GetRandom());
        }

    }
}