Beispiel #1
0
        /// <summary>
        /// Overloaded constructor used create an instance of the ChartModel class during serialization.
        /// The public properties of this class are set by this contructor as they are obtained from the
        /// IChart interface object passed as the parameter.
        /// </summary>
        /// <param name="chart">Specifies the IChart interface object to be serialized.</param>
        /// <remarks>
        /// The ChartModel class contains as serializable properties all other FlexChart objects appropriate
        /// for serializing the FlexChart control, it is only necessary to request serialization of the
        /// IChart object to store all information about the chart.  Subobjects do need not be serialized separately.
        /// </remarks>
        public ChartModel(IChart chart)
        {
            // simple properties
            ChartType = chart.ChartType;
            Header    = chart.Header;
            Footer    = chart.Footer;

            Stacking = chart.Stacking;

            {   // capture the XItems used for Axis Labeling.
                List <object> oItems = chart.GetXItems();
                if (oItems != null && oItems.Count > 0 && oItems[0].GetType() == typeof(string))
                {
                    List <string> sItems = new List <string>();
                    foreach (object o in oItems)
                    {
                        sItems.Add(o as string);
                    }
                    XItems = sItems;
                }
            }

            // styles
            Style             = StyleSerializer.StyleToString(chart.GetStyle(), chart as IBrushConverter);
            HeaderStyle       = StyleSerializer.StyleToString(chart.GetStyle("Header"), chart as IBrushConverter);
            FooterStyle       = StyleSerializer.StyleToString(chart.GetStyle("Footer"), chart as IBrushConverter);
            HeaderBorderStyle = StyleSerializer.StyleToString(chart.GetStyle("HeaderBorder"), chart as IBrushConverter);
            FooterBorderStyle = StyleSerializer.StyleToString(chart.GetStyle("FooterBorder"), chart as IBrushConverter);
            PlotStyle         = StyleSerializer.StyleToString(chart.GetStyle("Plot"), chart as IBrushConverter);
            SelectedStyle     = StyleSerializer.StyleToString(chart.GetStyle("Selected"), chart as IBrushConverter);

            // data
            Series = new List <SeriesModel>();
            foreach (var ser in chart.Series)
            {
                Series.Add(new SeriesModel(ser));
            }

            // axes
            //
            Axes = new List <AxisModel>();
            foreach (IAxis ax in chart.GetAxes())
            {
                Axes.Add(new AxisModel(ax));
            }
            // legend
            //
            Legend = new LegendModel(chart.Legend, chart);

            // ChartOptions
            Options = new OptionsModel(chart);

            // DataLabel
            DataLabel = new DataLabelModel(chart.DataLabel, chart);
        }