[Chartjs]-Return List<object> from webservice

2👍

List is not serializable to web method instead of this you can return object[].

[WebMethod]
    public object[] getProgram12Months(string usersessionid)
    {
        List<object> iData = new List<object>();
        List<string> labels = new List<string>();

        //First get distinct Month Name for select Year.
        string query1 = "SELECT DISTINCT TOP (100) PERCENT TimeFrame FROM dbo.CSQ_ProgramCount12Months ORDER BY TimeFrame ";

        string conn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
        SqlDataAdapter dap = new SqlDataAdapter(query1, conn);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        DataTable dtLabels = ds.Tables[0];


        foreach (DataRow drow in dtLabels.Rows)
        {
            labels.Add(drow["TimeFrame"].ToString());
        }
        iData.Add(labels.ToArray());

        return iData.ToArray();
    }

2👍

I resolved this by creating two classes an populating them. Thank you er-sho, your posts help lead me in the right direction.

public class ChartData2
    {
        public List<string> Legends;
        public List<int> AD;


    }

    public class Legend
    {
        public List<string> Months;
    }

Leave a comment