Exemplo n.º 1
0
        public static IChartable GetChart(string type)
        {
            IChartable chartable = null;

            if (!string.IsNullOrEmpty(type))
            {
                if (type.Equals("histogram", StringComparison.OrdinalIgnoreCase))
                {
                    chartable = new HistogramChart();
                    Console.WriteLine("初始化设置柱状图...");
                }
                else if (type.Equals("pie", StringComparison.OrdinalIgnoreCase))
                {
                    chartable = new PieChart();
                    Console.WriteLine("初始化设置饼状图...");
                }
                else if (type.Equals("line", StringComparison.OrdinalIgnoreCase))
                {
                    chartable = new LineChart();
                    Console.WriteLine("初始化设置折线图...");
                }
            }

            return(chartable);
        }
        //静态工厂方法
        public static Chart GetChart(string type)
        {
            Chart chart = null;

            if (type.Equals("histogram"))
            {
                chart = new HistogramChart();
                Console.WriteLine("初始化设置柱状图!");
            }
            else if (type.Equals("pie"))
            {
                chart = new PieChart();
                Console.WriteLine("初始化设置饼状图!");
            }
            else if (type.Equals("line"))
            {
                chart = new LineChart();
                Console.WriteLine("初始化设置折线图!");
            }
            return(chart);
        }