Welcome Guest Search | Active Topics |

multiple series
rdt
#1 Posted : Thursday, May 16, 2013 4:20:40 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/16/2013(UTC)
Posts: 16

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
is it possible that my model will be a list of my data
with an ability to iterate on it when i am creating the series ?
Dragan
#2 Posted : Friday, May 17, 2013 1:49:24 PM(UTC)
Rank: Advanced Member

Groups: Administrators, DataVizJavaScript, jQueryChart, jQueryDV, MvcChart, Registered
Joined: 1/3/2011(UTC)
Posts: 483

Thanks: 0 times
Was thanked: 87 time(s) in 87 post(s)
Hi,

You can specify your model as you want. In this sample:

www.jqchart.com/aspnetmvc/chart/ChartTypes/ColumnChart

This is the model:

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

namespace SamplesBrowser.Models
{
    public class ChartData
    {
        public static List<ChartData> GetData()
        {
            var data = new List<ChartData>();

            data.Add(new ChartData("A", 46, 78));
            data.Add(new ChartData("B", 35, 72));
            data.Add(new ChartData("C", 68, 86));
            data.Add(new ChartData("D", 30, 23));
            data.Add(new ChartData("E", 27, 70));
            data.Add(new ChartData("F", 85, 60));
            data.Add(new ChartData("D", 43, 88));
            data.Add(new ChartData("H", 29, 22));

            return data;
        }

        public ChartData(string label, double value1)
        {
            this.Label = label;
            this.Value1 = value1;
        }

        public ChartData(string label, double value1, double value2)
        {
            this.Label = label;
            this.Value1 = value1;
            this.Value2 = value2;
        }

        public string Label { get; set; }
        public double Value1 { get; set; }
        public double Value2 { get; set; }
    }
}


and this is how we defining it on the page.

@model IEnumerable<SamplesBrowser.Models.DateTimeXAxisChartData>
Best Regards,
Dragan Matek
jqChart Inc.
1 user thanked Dragan for this useful post.
rdt on 5/19/2013(UTC)
rdt
#3 Posted : Sunday, May 19, 2013 4:16:01 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/16/2013(UTC)
Posts: 16

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
i am familiar with this option
but he is not good for me
my 2 (or more) series are independent and not depend on each other x val
think of that as 2 different graphs on the same coordinate system

my model need to be something like a List<IEnumerable<point>> or object that contain IEnumerable of points

is there an y support for that?
thank you
Dragan
#4 Posted : Monday, May 20, 2013 2:35:03 PM(UTC)
Rank: Advanced Member

Groups: Administrators, DataVizJavaScript, jQueryChart, jQueryDV, MvcChart, Registered
Joined: 1/3/2011(UTC)
Posts: 483

Thanks: 0 times
Was thanked: 87 time(s) in 87 post(s)
If you have model like:

Code:
public class SeriesPoint
    {
        public SeriesPoint(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }

        public double X;
        public double Y;
    }


and your controller is:

Code:
public ActionResult Index()
        {
            List<List<SeriesPoint>> chartData = new List<List<SeriesPoint>>();

            for (int i = 0; i < 4; i++)
            {
                List<SeriesPoint> series = new List<SeriesPoint>();

                for (int j = 1; j <= 10; j++)
                {
                    SeriesPoint pt = new SeriesPoint(j, (i + 1) * 10 * j);

                    series.Add(pt);
                }

                chartData.Add(series);
            }

            return View(chartData);
        }


then your view should be like:

Code:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<IEnumerable<SeriesPoint>>>" %>

<%@ Import Namespace="JQChart.Web.Mvc" %>
<%@ Import Namespace="MvcTests.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div style='text-align: center;'>
        <%= Html.JQChart().Chart(Model)
                .ID("jqChart")
                .Width("400px")
                .Height("250px")
                .Series(series =>
                {
                    foreach (var item in Model)
                    {
                        series.Line()
                              .XValues(item.Select(el => el.X))
                              .YValues(item.Select(el => el.Y));
                    }
                })
                .Render()%>
    </div>
</asp:Content>
Best Regards,
Dragan Matek
jqChart Inc.
rdt
#5 Posted : Monday, May 20, 2013 2:53:06 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/16/2013(UTC)
Posts: 16

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
thank you
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

FlatEarth Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.083 seconds.