コード例 #1
0
ファイル: DonutChart.cs プロジェクト: superlee1/Mandrill
        /// <summary>
        ///     Donut Chart Data object.
        /// </summary>
        /// <param name="Names">Names of each data points.</param>
        /// <param name="Values">Values of each data point.</param>
        /// <returns name="Data">Donut Chart Data</returns>
        /// <search>data, donut, chart, donut chart data</search>
        public static DonutChartData Data(
            List <string> Names,
            List <double> Values)
        {
            List <DataPoint1> dataPoints = Names.Zip(Values, (x, y) => new DataPoint1 {
                name = x, value = y
            }).ToList();
            DonutChartData data = new DonutChartData();

            data.Data = new JavaScriptSerializer().Serialize(dataPoints);

            return(data);
        }
コード例 #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string filePath = null;

            if (!DA.GetData <string>(0, ref filePath))
            {
                return;
            }

            DonutChartData data = new DonutChartData();

            data.Data = new JavaScriptSerializer().Serialize(D3jsLib.Utilities.ChartsUtilities.Data1FromCsv(filePath));

            DA.SetData(0, data);
        }
コード例 #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DonutChartData  data  = null;
            DonutChartStyle style = null;

            if (!DA.GetData <DonutChartData>(0, ref data))
            {
                return;
            }
            if (!DA.GetData <DonutChartStyle>(1, ref style))
            {
                return;
            }

            D3jsLib.DonutChart.DonutChart chart = new D3jsLib.DonutChart.DonutChart(data, style);

            DA.SetData(0, chart);
        }
コード例 #4
0
ファイル: DonutChart.cs プロジェクト: superlee1/Mandrill
        /// <summary>
        ///     Donut Chart Data from CSV.
        /// </summary>
        /// <param name="FilePath">File Path to CSV file.</param>
        /// <returns name="Data">Donut Chart Data</returns>
        /// <search>csv, donut, chart, data</search>
        public static DonutChartData DataFromCSV(object FilePath)
        {
            // get full path to file as string
            // if File.FromPath is used it returns FileInfo class
            string _filePath = "";

            try
            {
                _filePath = (string)FilePath;
            }
            catch
            {
                _filePath = ((FileInfo)FilePath).FullName;
            }

            DonutChartData data = new DonutChartData();

            data.Data = new JavaScriptSerializer().Serialize(ChartsUtilities.Data1FromCsv(_filePath));

            return(data);
        }
コード例 #5
0
        public async Task <JsonResult> DonutMethod(int accountId)
        {
            //Initialization of data structures & lists
            string[]       basecolors = new string[] { "#6993FF", "#1BC5BD", "#8950FC", "#FFA800", "#F64E60" };
            DonutChartData chartData  = new DonutChartData();
            List <string>  labels     = new List <string>();
            List <int>     series     = new List <int>();
            List <string>  colors     = new List <string>();
            //Initialize dataset form database query of Transactions based on the account Id parameter
            List <Transaction> transactions = await db.Transactions.Include(t => t.BudgetItem).Where(t => t.AccountId == accountId).OrderBy(t => t.Id).ToListAsync();

            //Focus the dataset based on the results needed for the chart by Grouping the data
            List <ResultItem> budgetItems = transactions
                                            .GroupBy(t => t.BudgetItem)
                                            .Select(tb => new ResultItem //This supplemental class helps to contain the data
            {
                ItemName = tb.FirstOrDefault().BudgetItem.ItemName,
                Quantity = tb.Count(),
                Total    = tb.Sum(s => s.Amount)
            }).ToList();
            //Control variable for varying the colors
            int colorIndex = 0;

            //Loop over data results to load data in to lists
            foreach (ResultItem result in budgetItems)
            {
                labels.Add(result.ItemName);
                series.Add(result.Quantity);
                colors.Add(basecolors[colorIndex]);
                //Manage control variable for color variance
                _ = colorIndex < basecolors.Length ? colorIndex++ : colorIndex = 0;
            }

            //Convert data lists to arrays to return to the View
            chartData.labels = labels.ToArray();
            chartData.series = series.ToArray();
            chartData.colors = colors.ToArray();
            //Return results
            return(Json(chartData, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <string> names  = new List <string>();
            List <double> values = new List <double>();

            if (!DA.GetDataList <string>(0, names))
            {
                return;
            }
            if (!DA.GetDataList <double>(1, values))
            {
                return;
            }

            List <D3jsLib.DataPoint1> dataPoints = names.Zip(values, (x, y) => new D3jsLib.DataPoint1 {
                name = x, value = y
            }).ToList();
            DonutChartData data = new DonutChartData();

            data.Data = new JavaScriptSerializer().Serialize(dataPoints);

            DA.SetData(0, data);
        }
コード例 #7
0
ファイル: DonutChart.cs プロジェクト: gitgreencoder/Mandrill
        /// <summary>
        ///     Donut Chart Data from CSV.
        /// </summary>
        /// <param name="FilePath">File Path to CSV file.</param>
        /// <returns name="Data">Donut Chart Data</returns>
        /// <search>csv, donut, chart, data</search>
        public static DonutChartData DataFromCSV(object FilePath)
        {
            // get full path to file as string
            // if File.FromPath is used it returns FileInfo class
            string _filePath = "";

            try
            {
                _filePath = (string)FilePath;
            }
            catch
            {
                _filePath = ((FileInfo)FilePath).FullName;
            }

            List <DataPoint1> dataPoints = new List <DataPoint1>();
            var csv   = new List <string[]>();
            var lines = System.IO.File.ReadAllLines(_filePath);

            for (int i = 0; i < lines.Count(); i++)
            {
                string line = lines[i];
                if (i > 0)
                {
                    string lineName  = line.Split(',')[0];
                    double lineValue = Convert.ToDouble(line.Split(',')[1]);
                    dataPoints.Add(new DataPoint1 {
                        name = lineName, value = lineValue
                    });
                }
            }
            DonutChartData data = new DonutChartData();

            data.Data = dataPoints;

            return(data);
        }
コード例 #8
0
ファイル: DonutChart.cs プロジェクト: superlee1/Mandrill
 /// <summary>
 ///     Donut Chart object.
 /// </summary>
 /// <param name="Data">Donut Chart Data object.</param>
 /// <param name="Style">Donut Chart Style object.</param>
 /// <returns name="Chart">Donut Chart</returns>
 /// <search>donut chart, chart, donut</search>
 public static D3jsLib.DonutChart.DonutChart Chart(DonutChartData Data, DonutChartStyle Style)
 {
     D3jsLib.DonutChart.DonutChart chart = new D3jsLib.DonutChart.DonutChart(Data, Style);
     return(chart);
 }