Beispiel #1
0
        /// <summary>
        /// 数据部分转成js代码
        /// </summary>
        /// <param name="series"></param>
        /// <returns></returns>
        private string SeriesDataToString(ChartsSeries series)
        {
            string seriesdata = "{ name: '" + series.SeriesName + "',data:[";

            foreach (var item in series.SeriesData)
            {
                seriesdata += "['" + item.Key + "'," + item.Value + "],";
            }
            seriesdata  = seriesdata.TrimEnd(',');
            seriesdata += "] }";
            return(seriesdata);
        }
Beispiel #2
0
        public override void DataBind()
        {
            if (string.IsNullOrEmpty(DataKey) || string.IsNullOrEmpty(DataValue))
            {
                return;
            }
            if (DataSource != null)
            {
                System.Type type = DataSource.GetType();
                if (type.Name.Equals("DataTable"))
                {
                    DataTable dt = (DataTable)DataSource;
                    if (dt.Rows.Count <= 0)
                    {
                        return;
                    }
                    if (dt.Columns.Contains(DataKey) && dt.Columns.Contains(DataValue))
                    {
                        var dic = new Dictionary <object, object>();
                        foreach (DataRow r in dt.Rows)
                        {
                            dic.Add(r[DataKey], r[DataValue]);
                        }
                        Series = new ChartsSeries {
                            SeriesName = DataName, SeriesData = dic
                        };
                    }
                }

                if (type.Name.Equals("DataSet"))
                {
                    DataSet ds = (DataSet)DataSource;
                    if (ds.Tables.Count <= 0)
                    {
                        return;
                    }
                    var list = new List <ChartsSeries>();
                    for (int i = 0; i < ds.Tables.Count; i++)
                    {
                        DataTable dt = ds.Tables[i];
                        if (dt.Rows.Count <= 0)
                        {
                            continue;
                        }
                        if (dt.Columns.Contains(DataKey) && dt.Columns.Contains(DataValue))
                        {
                            var dic = new Dictionary <object, object>();
                            foreach (DataRow r in dt.Rows)
                            {
                                dic.Add(r[DataKey], r[DataValue]);
                            }
                            ChartsSeries cs = new ChartsSeries {
                                SeriesName = GetDataName(i), SeriesData = dic
                            };
                            list.Add(cs);
                        }
                    }
                    SeriesList = list;
                }
            }
        }