コード例 #1
0
        /// <summary>
        /// Serializes the chart.
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <returns></returns>
        private static IDictionary<string, object> serializeChart(Graph graph)
        {
            Type typeDateTime = typeof(DateTime);

            Dictionary<string, int> dicXtype = new Dictionary<string, int>();

            //cache x values if we are working with strings, we will need ticker tape to display values
            if (graph.Series.Count > 0 &&
                graph.Series[0].Axis.Count > 0)
            {
                for (int i = 0; i < graph.Series[0].Axis.Count; i++)
                {
                    dicXtype.Add(graph.Series[0].Axis[i].X.ToString(), i);
                }
            }

            bool yyIsUsed = graph.YYLabel != null && graph.YYLabel.Length > 0;

            Dictionary<string, object> dictValueToObject = new Dictionary<string, object>();
            ArrayList arrayList = new ArrayList();

            Dictionary<string, object> dictYYToValues = new Dictionary<string, object>();

            foreach (GraphSeries series in graph.Series)
            {
                ArrayList arrayListYY = new ArrayList();

                Dictionary<string, object> dictList = new Dictionary<string, object>();
                dictList.Add("label", series.Name);

                ArrayList arrayListAxis = new ArrayList();

                foreach (GraphAxis axis in series.Axis)
                {
                    ArrayList arrayListXY = new ArrayList();

                    if (graph.XType == typeDateTime)
                    {
                        arrayListXY.Add(axis.X);
                    }
                    else
                    {
                        arrayListXY.Add(dicXtype[axis.X.ToString()]);
                    }

                    arrayListXY.Add(axis.Y);

                    if(yyIsUsed)
                    {

                        arrayListYY.Add(axis.YY);
                    }

                    arrayListAxis.Add(arrayListXY);
                }

                if (yyIsUsed)
                {
                    dictYYToValues.Add(series.Name, arrayListYY);
                }

                dictList.Add("data", arrayListAxis);
                arrayList.Add(dictList);
            }

            dictValueToObject.Add("Series", arrayList);

            ArrayList arrayListTicker = new ArrayList();
            foreach (KeyValuePair<string, int> ticker in dicXtype)
            {
                ArrayList arrayListTickerValues = new ArrayList();
                arrayListTickerValues.Add(ticker.Value);
                arrayListTickerValues.Add(ticker.Key);
                arrayListTicker.Add(arrayListTickerValues);
            }

            dictValueToObject.Add("Ticker", arrayListTicker);

            if (yyIsUsed)
            {
                dictValueToObject.Add("YY", dictYYToValues);
            }

            return dictValueToObject;
        }
コード例 #2
0
        /// <summary>
        /// Serializes the chart pie.
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <returns></returns>
        private static IDictionary<string, object> serializeChartPie(Graph graph)
        {
            ArrayList arrayList = new ArrayList();
            GraphSeries series = graph.Series[0];

            Dictionary<string, object> dictValueToObject = new Dictionary<string, object>();
            foreach (GraphAxis graphAxis in series.Axis)
            {
                Dictionary<string, object> dictList = new Dictionary<string, object>();
                dictList.Add("label", graphAxis.X);
                dictList.Add("data", graphAxis.Y);
                arrayList.Add(dictList);
            }

            dictValueToObject.Add("Series", arrayList);
            return dictValueToObject;
        }