thiru
thiru

Reputation: 173

How to generate Line chart

i am trying to generate Line chart in mvc using jQuery..

here is my controller code:

 List<Dictionary<string, object>> result = null;

                result = client.GetApiRequest("api/TurnoverPieChart/Get?year=" + year + "&repType=" + repType).Result;

                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

                StringBuilder pJsonData = new StringBuilder();
                foreach (Dictionary<string, object> pData in result)
                {
                    StringBuilder myJsonString = new StringBuilder();
                    //Dictionary<int, List<int>> MyObj = (Dictionary<int, List<int>>)pData;
                    Dictionary<string, long[]> MyObj1 = new Dictionary<string, long[]>();
                    Dictionary<string, string> MyObj2 = new Dictionary<string, string>();

                    short count = 0;
                    foreach (var pd in pData)
                    {
                        if (count == 1)
                        {
                            long[] arr = ((IEnumerable)pd.Value).Cast<object>()
                                 .Select(x => Convert.ToInt64(x.ToString()))
                                 .ToArray();

                            MyObj1.Add(pd.Key, arr);
                        }
                        else
                        {
                            MyObj2.Add(pd.Key, pd.Value.ToString());
                        }
                        myJsonString.Append(count == 0 ? serializer.Serialize(MyObj2) : serializer.Serialize(MyObj1));
                        count++;
                    }
                    pJsonData.Append(myJsonString.ToString().Replace("}{", ","));
                }

                string finalJsonData = "[" + pJsonData.ToString().Replace("}{", "},{") + "]";

                return View(finalJsonData);

in the "finalJsonData" the data is like

[{"Label":"Solapur","Data":[25836,94698,49,5149,465153,5329,6489371,11169,9369,9369,653149,645149]}]

everything is fine till here.. now my question is like how to handle this jsondata in my view to generate line chart. i am want a sample using ajax-call in jquery........

Upvotes: 0

Views: 63

Answers (2)

Vladimir Georgiev
Vladimir Georgiev

Reputation: 1949

This is a nice example of a Line chart in ASP.NET MVC, as well as other technologies like pure JavaScript and ASP.NET.

Upvotes: 0

Kiran Bhagat
Kiran Bhagat

Reputation: 73

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
 <script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
     </script>

add this script to your page. and then draw chart

Upvotes: 1

Related Questions