/// <summary>
        /// AxisModel.Load is used to set the properties of an existing Axis object in a FlexChart based control.
        /// The values used are those stored in an existing AxisModel class object that is typically created and set by
        /// a standard serializer during deserialization.
        /// </summary>
        /// <param name="ax">Specifies an existing instance of an Axis class object.</param>
        /// <param name="am">Specifies an existing instannce of an AxisModel class object created by a
        ///                  a standard serializer during deserialization.</param>
        public static void Load(Axis ax, AxisModel am)
        {
            ax.Position          = am.Position;
            ax.Origin            = am.Origin;
            ax.Reversed          = am.Reversed;
            ax.Labels            = am.Labels;
            ax.MajorTickMarks    = am.MajorTickMarks;
            ax.MajorGrid         = am.MajorGrid;
            ax.MajorUnit         = am.MajorUnit;
            ax.MinorTickMarks    = am.MinorTickMarks;
            ax.MinorGrid         = am.MinorGrid;
            ax.MinorUnit         = am.MinorUnit;
            ax.LogBase           = am.LogBase;
            ax.AxisLine          = am.AxisLine;
            ax.LabelAlignment    = am.LabelAlignment;
            ax.LabelAngle        = am.LabelAngle;
            ax.Min               = am.Min;
            ax.Max               = am.Max;
            ax.Format            = am.Format;
            ax.Title             = am.Title;
            ax.OverlappingLabels = am.OverlappingLabels;

            //// styles
            ((IAxis)ax).SetStyle(StyleSerializer.StyleFromString(am.Style), "_");
            ((IAxis)ax).SetStyle(StyleSerializer.StyleFromString(am.MajorGridStyle), "_MajorGrid");
            ((IAxis)ax).SetStyle(StyleSerializer.StyleFromString(am.MinorGridStyle), "_MinorGrid");
            ((IAxis)ax).SetStyle(StyleSerializer.StyleFromString(am.TitleStyle), "_Title");
        }
Exemplo n.º 2
0
        /// <summary>
        /// ChartModel.Load is used to set the properties of an existing FlexChart object in a FlexChart based control.
        /// The values used are those stored in an existing ChartModel class object that is typically created and set by
        /// a standard serializer during deserialization.
        /// </summary>
        /// <param name="chart">Specifies an existing instance of a FlexChart class object.</param>
        /// <param name="model">Specifies an existing instannce of a ChartModel class object created by a
        ///                  a standard serializer during deserialization.</param>
        public static void Load(FlexChart chart, ChartModel model)
        {
            // simple properties
            chart.ChartType = model.ChartType;
#if WINFORMS
            chart.Header.Content = model.Header;
            chart.Footer.Content = model.Footer;
#endif

#if WPF
            chart.Header = model.Header;
            chart.Footer = model.Footer;
#endif
            chart.Stacking = model.Stacking;

            if (model.XItems != null && model.XItems.Count > 0)
            {
                chart.BindingX = "X";
                List <object> ds = new List <object>();
                foreach (string s in model.XItems)
                {
                    ds.Add(new { X = s });
                }
#if WINFORMS
                chart.DataSource = ds;
#endif
#if WPF
                chart.ItemsSource = ds;
#endif
            }

            // Load Axes before series so they are available.
            List <Axis> axes = new List <Axis>()
            {
                chart.AxisX, chart.AxisY
            };
            for (int iax = 2; iax < model.Axes.Count; iax++)
            {
                axes.Add(new Axis());
            }

            for (int iax = 0; iax < model.Axes.Count; iax++)
            {
                AxisModel.Load(axes[iax], model.Axes[iax]);
            }

            // data
            var series = chart.Series;
            series.Clear();
            foreach (var sm in model.Series)
            {
                var ser = new Series();
                series.Add(ser);
                SeriesModel.Load(ser, sm);

                if (sm.XAxisIndex > 0 && sm.XAxisIndex < axes.Count)
                {
                    ser.AxisX = axes[sm.XAxisIndex];
                }

                if (sm.YAxisIndex > 0 && sm.YAxisIndex < axes.Count)
                {
                    ser.AxisY = axes[sm.YAxisIndex];
                }
            }

            // styles
            ((IStyleProvider)chart).SetStyle(StyleSerializer.StyleFromString(model.Style), null);
            ((IStyleProvider)chart).SetStyle(StyleSerializer.StyleFromString(model.HeaderStyle), "Header");
            ((IStyleProvider)chart).SetStyle(StyleSerializer.StyleFromString(model.FooterStyle), "Footer");
            ((IStyleProvider)chart).SetStyle(StyleSerializer.StyleFromString(model.HeaderBorderStyle), "HeaderBorder");
            ((IStyleProvider)chart).SetStyle(StyleSerializer.StyleFromString(model.FooterBorderStyle), "FooterBorder");
            ((IStyleProvider)chart).SetStyle(StyleSerializer.StyleFromString(model.PlotStyle), "Plot");
            ((IStyleProvider)chart).SetStyle(StyleSerializer.StyleFromString(model.SelectedStyle), "Selected");

            // legend
            LegendModel.Load(chart, model.Legend);

            // ChartOptions
            OptionsModel.Load(chart.Options, model.Options);

            // DataLabel
            DataLabelModel.Load(chart.DataLabel, model.DataLabel);
        }