65.9K
CodeProject 正在变化。 阅读更多。
Home

内部供应链,通过 200 多个 3D 图表报告实现可视化 - 第二部分

starIconstarIconstarIconstarIconstarIcon

5.00/5 (14投票s)

2009年10月8日

CPOL

4分钟阅读

viewsIcon

56180

downloadIcon

5330

本文聚焦于内部供应链管理系统的图表报告可视化,并提供用于管理和监控业务流程中产生活动的评估工具,从而为及时准确的业务决策铺平道路。

引言

本文聚焦于内部供应链管理过程的可视化。它是《内部供应链可视化》的续篇。在本文中,目标是利用 MSChart 实现,从而提供评估工具。解决方案包括条形图、折线图、面积图、饼图、帕累托图和蜡烛图。这些图表根据各自的属性进一步分类。

报告分为分类报告、累计报告和变化率报告。分类报告提供特定项目或商品的背景信息,并在此基础上分析其他子上下文。累计报告提供所有项目或侧移项目上下文的背景信息。

分类和累计报告进一步细分为分类成本、分类数量、累计成本、累计数量。

分类成本报告

分类成本报告勾勒出在途、当前、在制品、已预留、已消耗和已浪费的原材料的成本视角,用于采购;以及即将到货、当前、在制品、销售退回、已预留、已售出和已浪费的成品,用于仓库。

材料分类成本报告

p_s_c_bar.jpg

成品分类成本报告

w_s_c_line.jpg

分类数量报告

分类数量报告勾勒出在途、当前、在制品、已预留、已消耗和已浪费的原材料的数量视角,用于采购;以及即将到货、当前、在制品、销售退回、已预留、已售出和已浪费的成品,用于仓库。

材料分类数量报告

p_s_q_bar.jpg

p_s_q_line.jpg

成品分类数量报告

w_s_q_bar.jpg

w_s_q_line.jpg

累计成本报告

累计成本报告勾勒出在途、当前、在制品、已预留、已消耗和已浪费的原材料的成本视角,用于采购;以及即将到货、当前、在制品、销售退回、已预留、已售出和已浪费的成品,用于仓库。

材料累计成本报告

p_c_c_bar.jpg

p_c_c_line.jpg

成品累计成本报告

w_c_c_bar.jpg

w_c_c_line.jpg

w_c_c_net_profit_bar.jpg

w_c_c_net_profit_line.jpg

w_c_c_net_profit_pie.jpg

图表工作

Microsoft 图表控件包含 `Chart`、`ChartArea` 和 `Series` 类。这些对象的协同工作构成了一个图表报告。下面是对它的简要描述。

Chart 类

`Chart` 控件为图表报告提供了一个画布。它充当 `chartArea` 的容器。因此,它可以看作是图表将要呈现的框架。`SetChart()` 方法用于在解决方案中设置图表的属性。它分配标题并设置报告的图例属性。

System.Windows.Forms.DataVisualization.Charting.Chart SetChart()
        {
            System.Windows.Forms.DataVisualization.Charting.Chart chartTemp = 
		new System.Windows.Forms.DataVisualization.Charting.Chart();
            chartTemp.BackColor = System.Drawing.Color.Gainsboro;
            chartTemp.BackGradientStyle = 
	     System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            chartTemp.BackSecondaryColor = System.Drawing.Color.Silver;
            chartTemp.BorderlineColor = System.Drawing.Color.FromArgb
		(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            chartTemp.BorderlineDashStyle = 
		System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            chartTemp.BorderlineWidth = 3;
            chartTemp.BorderSkin.SkinStyle = 
		System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Sunken;

            if (_charts == Charts.Pie)
            {
                chartTemp.ChartAreas.Add(SetPieChartArea());
            }
            else
            {
                chartTemp.ChartAreas.Add(SetChartArea());
            }
            
            chartTemp.Legends.Add(SetLegend());
            chartTemp.Location = new System.Drawing.Point(10, 10);
            chartTemp.Name = "chart";
            chartTemp.Size = new System.Drawing.Size(1000, 450);
            chartTemp.TabIndex = 0;
            
            return chartTemp;
        }

ChartArea 类

`ChartArea` 是 `Chart` 类的一个内容。它被添加为 `Chart` 类中的集合。它提供了图表报告除了数据可视化之外的内在可视化,数据可视化由 Series 完成,稍后将讨论。`SetChartArea()` 方法设置图表区域的属性,这些属性定义了要生成的报告的样式,以及 x 轴和 y 轴的属性。

ChartArea SetChartArea()
        {
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = 
		new System.Windows.Forms.DataVisualization.Charting.ChartArea();


            chartArea1.Area3DStyle.Inclination = 15;
            chartArea1.Area3DStyle.IsClustered = true;
            chartArea1.Area3DStyle.IsRightAngleAxes = false;
            chartArea1.Area3DStyle.LightStyle = 
	      System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
            chartArea1.Area3DStyle.Perspective = 7;
            chartArea1.Area3DStyle.Rotation = 20;
            chartArea1.Area3DStyle.WallWidth = 10;
            chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font
			("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisX.LineColor = System.Drawing.Color.Teal;
            chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.Teal;
            chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font
			("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb
		(((int)(((byte)(64)))), ((int)(((byte)(64)))), 
		((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.Teal;
            chartArea1.BackColor = System.Drawing.Color.Gainsboro;
            chartArea1.BackGradientStyle = 
	      System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            chartArea1.BackSecondaryColor = System.Drawing.Color.Silver;
            chartArea1.BorderColor = System.Drawing.Color.Teal;
            chartArea1.BorderDashStyle = 
	      System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            chartArea1.Name = "Default";
            chartArea1.ShadowColor = System.Drawing.Color.Transparent;

            return chartArea1;
        }

Series 类

`Series` 类位于 `System.Windows.Forms.DataVisualization.Charting` 命名空间下。`Series` 类对象是 `ChartArea` 类的内容。它们作为集合被添加到 `ChartArea` 对象中。因此,我们可以在同一个 `chartArea` 中拥有多种类型的图表,用于比较报告。`Series` 类对象是 `DataPoints` 对象的集合。可以使用 `series.Points.AddXY(ts.Days, amount)` 方法收集 `DataPoints`。`addXY( , )` 方法的第一个参数定义了点的 x 坐标,y 坐标从第二个参数收集。当 series 类型设置为 `SeriesChartType.Line` 时,`DataPoints` 将作为生成连接所有 `datapoints` 的集合的点的作用。如果设置为 `SeriesChartType.Column`,则 y 坐标将是垂直条的高度,其在基座上的位置由 x 坐标决定。蜡烛图也是如此。

帕累托图

帕累托图是一种组合图。它是条形图和折线图的组合。条形图在 x 轴上显示产品或材料,在 y 轴上显示金额或数量。在同一图表中,组合的折线图显示前面材料的累计总和。`InitializeParetoChart()` 和 `ParetoChartTypeLoad()` 是生成此图表的基本方法。

#region Pareto Chart
        private void InitializeParetoChart()
        {
            // Initialize chart control
            this.chart = SetChart();

            // Suspend Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
            this.SuspendLayout();
        
            // setting attributes associated with pareto chart
            this.chart.ChartAreas[0].AxisX.Interval = 1;
            this.chart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
            this.chart.ChartAreas[0].AxisX.IntervalOffset = 1;
            this.chart.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Days;
            this.chart.ChartAreas[0].AxisX.LabelAutoFitStyle |= 
				LabelAutoFitStyles.LabelsAngleStep90;
            this.chart.ChartAreas[0].AxisY2.IsLabelAutoFit = false;
            
            // Add Chart control to Panel
            this.ReportPanel.Controls.Add(this.chart);
            
            // populating the chart
            ParetoChartTypeLoad();

            // Resume Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
            this.ResumeLayout(false);
        }
        void MakeParetoChart(System.Windows.Forms.DataVisualization.Charting.Chart chart, 
		string srcSeriesName, string destSeriesName)
        {
            // get name of the ChartAre of the source series
            string strChartArea = chart.Series[srcSeriesName].ChartArea;

            // ensure the source series is a column chart type
            chart.Series[srcSeriesName].ChartType = SeriesChartType.Column;

            // sort the data in the series to be by values in descending order
            chart.DataManipulator.Sort(PointSortOrder.Descending, srcSeriesName);

            // find the total of all points in the source series
            double total = 0.0;
            foreach (DataPoint pt in chart.Series[srcSeriesName].Points)
                total += pt.YValues[0];
            
            // set the max value on the primary axis to total
            chart.ChartAreas[strChartArea].AxisY.Maximum = total;
            
            // create the destination series and add it to the chart
            Series destSeries = new Series(destSeriesName);
            chart.Series.Add(destSeries);

            // ensure the destination series is a Line or Spline chart type
            destSeries.ChartType = SeriesChartType.Line;
            destSeries.BorderWidth = 3;

            // assign the series to the same chart area as the column chart
            destSeries.ChartArea = chart.Series[srcSeriesName].ChartArea;

            // assign this series to use the secondary axis and set it maximum to be 100%
            destSeries.YAxisType = AxisType.Secondary;
            chart.ChartAreas[strChartArea].AxisY2.Maximum = 100;

            // locale specific percentage format with no decimals
            chart.ChartAreas[strChartArea].AxisY2.LabelStyle.Format = "P00";

            // turn off the end point values of the primary X axis
            chart.ChartAreas[strChartArea].AxisX.LabelStyle.IsEndLabelVisible = false;

            // for each point in the source series find % of total and assign to series
            double percentage = 0.0;

            foreach (DataPoint pt in chart.Series[srcSeriesName].Points)
            {
                percentage += (pt.YValues[0] / total * 100.0);
                destSeries.Points.Add( ( Math.Round(percentage, 2) ) );
            }
        }
        private void ParetoChartTypeLoad()
        {
            // Accessing datasource
            Main.ChartDialog.PlantSegregation pseg =
               new ISCMS.Main.ChartDialog.PlantSegregation
               (_plantSegment, _charts, _chartBy, _is_Segregation, this);

            rows = pseg.Process();
            
            // Validating data for the report
            if (rows.Length == 0)
            {
                ReportPanel.Controls.Clear();
                Hasan.CMessageBoxSmall.ShowBox("No record has been found, 
		to generate Reports", (int)Hasan.CMessageBox.Type.Exclamation, 
			Location.X, Location.Y);
                return;
            }

            // Set report title
            this.chart.Titles.Add(SetTitle());

            // Initialize Series
            System.Windows.Forms.DataVisualization.Charting.Series series = 
		new System.Windows.Forms.DataVisualization.Charting.Series();
            series.BorderColor = System.Drawing.Color.FromArgb
		(((int)(((byte)(180)))), ((int)(((byte)(26)))), 
		((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series.ChartArea = "Default";
            series.Legend = "Default";
            series.Name = "Default";
            
            // Add Series to a chart
            this.chart.Series.Add(series);
            
            chart.Series["Default"].Points.Clear();
            int amount = 0;
            
            // provide series with datapoints 
            for (int i = 0; i < rows.Length; i++)//
            {
                amount = pseg.ProcessItem(i);
                if (amount == 0)
                    continue;
                chart.Series["Default"].Points.AddXY(rows[i]["Name"].ToString(), amount);
            }

            // Make Pareto Chart
            if (chart.Series.Count > 1)
                chart.Series.RemoveAt(1);
            MakeParetoChart(chart, "Default", "Pareto");

            // Set chart types for output data
            chart.Series["Pareto"].ChartType = SeriesChartType.Line;

            // Set Color of line Pareto chart
            chart.Series["Pareto"].Color = Color.FromArgb(252, 180, 65);

            // set the markers for each point of the Pareto Line
            chart.Series["Pareto"].IsValueShownAsLabel = false;
            chart.Series["Pareto"].MarkerColor = Color.Red;
            chart.Series["Pareto"].MarkerStyle = MarkerStyle.None;
            chart.Series["Pareto"].MarkerBorderColor = Color.MidnightBlue;
            chart.Series["Pareto"].MarkerSize = 8;
            chart.Series["Pareto"].LabelFormat = "0.#";          }
        #endregion 

w_c_c_pareto.jpg

折线图

此图表用于根据成本和数量表示永久库存。生成此图表的主要组成部分是 InitializeLineCurvesChart() 和 LineCurvesChartTypeLoad()。

 #region Line Chart
        private void InitializeLineCurvesChart()
        {
            // Initialize chart control
            this.chart = SetChart();

            // Suspend Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
            this.SuspendLayout();
            
            // Add Chart control to Panel
            this.ReportPanel.Controls.Add(this.chart);

            // populating the chart
            LineCurvesChartTypeLoad();

            // Resume Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
            this.ResumeLayout(false);
        }
        private void LineCurvesChartTypeLoad()
        {
            // Accessing datasource
            Main.ChartDialog.PlantSegregation pseg =
                new ISCMS.Main.ChartDialog.PlantSegregation
                (_plantSegment, _charts, _chartBy, _is_Segregation, this);
            
            rows = pseg.Process();

            // Validating data for the report
            if (rows.Length == 0)
            {
                ReportPanel.Controls.Clear();
                Hasan.CMessageBoxSmall.ShowBox("No record has been found, 
		to generate Reports", (int)Hasan.CMessageBox.Type.Exclamation, 
		Location.X, Location.Y);
                return;
            }

            // Set title for Report
            this.chart.Titles.Add( SetTitle());

            // Initialize Series
            System.Windows.Forms.DataVisualization.Charting.Series series = 
		new System.Windows.Forms.DataVisualization.Charting.Series();
            series.BorderColor = System.Drawing.Color.Transparent;
            series.BorderWidth = 3;
            series.ChartArea = "Default";
            series.ChartType = 
		System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
            series.Color = _serial_Color;
            series.Legend = "Default";
            series.MarkerSize = 4;
            series.MarkerStyle = 
		System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series.Name = "series";
            series.ShadowColor = System.Drawing.Color.Gainsboro;
            series.ShadowOffset = 2;
            series.XValueType = 
		System.Windows.Forms.DataVisualization.Charting.ChartValueType.Date;
            series.YValueType = 
		System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series.BorderColor = System.Drawing.Color.Transparent;

            TimeSpan ts = DateTime.Now - new DateTime(1900, 1, 1);
            double days = ts.Days;
            double days2 = days;
            int amount = 0;
            int perviousAmount = 0;

            // providing series datapoints
            for (int pointIndex = 0; pointIndex < rows.Length; pointIndex++)
            {
                amount = pseg.ProcessItem(pointIndex);
                ts = DateTime.Parse(rows[pointIndex]["Date"].ToString()) - 
						new DateTime(1900, 1, 1);
                if (perviousAmount == 0 && pointIndex == 0)
                {
                    series.Points.AddXY(ts.Days, amount);
                    perviousAmount = amount;
                    continue;
                }

                if (pointIndex == (rows.Length - 1))
                {
                    series.Points.AddXY(ts.Days, amount);
                    continue;
                }

                if( perviousAmount != amount )
                {
                    series.Points.AddXY(ts.Days, amount);
                    perviousAmount = amount;
                    continue;
                }
            }

            // Select chart type
            switch (combChartType.Text)
            {
                case "Line":
                    if (!chkAreaChart.Checked)
                    {
                        series.ChartType = SeriesChartType.Line;
                    }
                    else
                    {
                        series.ChartType = SeriesChartType.Area;
                    }
                    break;
                case "Spline":
                    if (!chkAreaChart.Checked)
                    {
                        series.ChartType = SeriesChartType.Spline;
                    }
                    else
                    {
                        series.ChartType = SeriesChartType.SplineArea;
                    }
                    break;
                case "StepLine":
                    if (!chkAreaChart.Checked)
                    {
                        series.ChartType = SeriesChartType.StepLine;
                    }
                    else
                    {
                        series.ChartType = SeriesChartType.SplineArea;
                    }
                    break;
            }
           
            // Display label on the chart
            if (chkPointLabel.Checked)
            {
                series.IsValueShownAsLabel = true;
            }
            else
            {
                series.IsValueShownAsLabel = false;
            }

            // Display margin on sides of a chart
            if (chkMargin.Checked)
                chart.ChartAreas["Default"].AxisX.IsMarginVisible = true;
            else
                chart.ChartAreas["Default"].AxisX.IsMarginVisible = false;

            // Display 3D Chart
            if (chkDisplay3D.Checked)
                chart.ChartAreas["Default"].Area3DStyle.Enable3D = true;
            else
                chart.ChartAreas["Default"].Area3DStyle.Enable3D = false;

            // Add Series to a chart
            this.chart.Series.Add(series);
        }
        #endregion

p_s_c_line.jpg

饼图

这是一个累计图,可以通过调用 `InitializePieCollection()` 方法生成。其代码如下:

#region Pie Chart
        private void InitializePieCollection()
        {
            // Initialize chart control
            this.chart = SetChart();

            // Suspend Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
            this.SuspendLayout();

            // setting attributes associated with Pie chart
            this.chart.Legends[0].Enabled = true;
            this.chart.Legends[0].IsEquallySpacedItems = true;
            
            // Add Chart control to Panel
            this.ReportPanel.Controls.Add(this.chart);

            // populating the chart
            PieChartTypeLoad();

            // Resume Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
            this.ResumeLayout(false);
        }
        private void PieChartTypeLoad()
        {
            // Accessing datasource
            Main.ChartDialog.PlantSegregation pseg =
                new ISCMS.Main.ChartDialog.PlantSegregation
                (_plantSegment, _charts, _chartBy, _is_Segregation, this);

            rows = pseg.Process();

            // Validating data for the report
            if (rows.Length == 0)
            {
                ReportPanel.Controls.Clear();
                Hasan.CMessageBoxSmall.ShowBox("No record has been found, 
		to generate Reports", (int)Hasan.CMessageBox.Type.Exclamation, 
		Location.X, Location.Y);
                return;
            }

            // Set report title
            this.chart.Titles.Add(SetTitle());

            // Initialize Series
            System.Windows.Forms.DataVisualization.Charting.Series series = 
		new System.Windows.Forms.DataVisualization.Charting.Series();
            series.BorderColor = System.Drawing.Color.FromArgb
		(((int)(((byte)(64)))), ((int)(((byte)(64)))), 
		((int)(((byte)(64)))), ((int)(((byte)(64)))));
            series.ChartArea = "Area1";
            series.ChartType = 
		System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
            series.Color = System.Drawing.Color.FromArgb
		(((int)(((byte)(180)))), ((int)(((byte)(65)))), 
		((int)(((byte)(140)))), ((int)(((byte)(240)))));
            series.CustomProperties = "DoughnutRadius=15, 
		PieDrawingStyle=Concave, CollectedLabel=Other, MinimumRelative" +
                "PieSize=10";
            series.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, 
		System.Drawing.FontStyle.Bold);
            series.Label = "#PERCENT{P1}";
            series.Legend = "Default";
            series.MarkerStyle = 
		System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series.Name = "Default";
            series.XValueType = 
		System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series.YValueType = 
		System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            
            System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint1 = 
		new System.Windows.Forms.DataVisualization.Charting.DataPoint(0, 0);
            int amount = 0;

            // providing series with datapoints 
            for (int i = 0; i < rows.Length; i++)
            {
                amount = pseg.ProcessItem(i);
                dataPoint1 = 
	       new System.Windows.Forms.DataVisualization.Charting.DataPoint(0, amount);
                dataPoint1.CustomProperties = "OriginalPointIndex=" + i.ToString();
                dataPoint1.IsValueShownAsLabel = false;
                dataPoint1.LegendText = rows[i]["Name"].ToString();
                
                if( !chkPercentage.Checked )
                    dataPoint1.Label = rows[i]["Name"].ToString();
                series.Points.Add(dataPoint1);
            }

            // Add Series to a chart
            this.chart.Series.Add(series);

            // Set series font
            chart.Series[0].Font = new Font("Trebuchet MS", 8, FontStyle.Bold);
            chart.Series[0]["CollectedToolTip"] = "Other";
            chart.Series["Default"]["PieLabelStyle"] = "Outside";

            // Merge smaller slice into one
            if (ChkCollectSlices.Checked)
            {
                chart.Series["Default"]["CollectedThreshold"] = combThershold.Text;
                combThershold.Enabled = true;
            }
            else
            {
                combThershold.Enabled = false;
            }

            // Remove supplemental series and chart area if they already exist
            if (chart.Series.Count > 1)
            {
                chart.Series.RemoveAt(1);
                chart.ChartAreas.RemoveAt(1);
                // Reset automatic position for the default chart area
                chart.ChartAreas["Default"].Position.Auto = true;
            }

            pieHelper = new PieCollectedDataHelper(chart);
            pieHelper.CollectedLabel = String.Empty;

            if (chkSupplementChart.Checked)
            {
                chart.Series["Default"]["PieLabelStyle"] = "Outside";

                // Set the percentage of the total series values. This value determines
                // if the data point value is a "small" value and 
	       // should be shown as collected.
                pieHelper.CollectedPercentage =  double.Parse(combThershold.Text);

                // Indicates if small segments should be shown as one 
                // "collected" segment in the original series.
                pieHelper.ShowCollectedDataAsOneSlice = chkCollectSmallSegment.Checked;

                // Size ratio between the original and supplemental chart areas.
                // Value of 1.0f indicates that same area size will be used.
                if (combSupplementSize.SelectedIndex == 0)
                {
                    pieHelper.SupplementedAreaSizeRatio = 0.9f;
                }
                else if (combSupplementSize.SelectedIndex == 1)
                {
                    pieHelper.SupplementedAreaSizeRatio = 1.0f;
                }
                else if (combSupplementSize.SelectedIndex == 2)
                {
                    pieHelper.SupplementedAreaSizeRatio = 1.1f;
                }

                // Set position in relative coordinates 
                // ( 0,0 - top left corner; 100,100 - bottom right corner)
                // where original and supplemental pie charts should be placed.
                pieHelper.ChartAreaPosition = new RectangleF(3f, 3f, 93f, 96f);

                // Show supplemental pie for the "Default" series
                pieHelper.ShowSmallSegmentsAsSupplementalPie("Default");
            }
            else
            {
                chart.Series["Default"]["PieLabelStyle"] = "Outside";
                chart.Series["Default"].LabelBackColor = Color.Empty;
            }

            // setting time interval for animated Pie chart
            timer1.Interval = 10;
            timer1.Enabled = true;
        }
        #endregion

p_c_c_pie.jpg

条形图

条形图的代码如下

 #region Bar Chart
        private void InitializeBarColumn()
        {
            // Initialize chart control
            this.chart = SetChart();

            // Suspend Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
            this.SuspendLayout();
            
            // Add Chart control to Panel
            this.ReportPanel.Controls.Add(this.chart);

            // populating the chart
            BarColumnChartTypeLoad();

            // Resume Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
            this.ResumeLayout(false);
        }
        private void BarColumnChartTypeLoad()
        {
            // Accessing datasource
            Main.ChartDialog.PlantSegregation pseg =
                new ISCMS.Main.ChartDialog.PlantSegregation
                (_plantSegment, _charts, _chartBy, _is_Segregation, this);

            rows = pseg.Process();

            // Validating data for the report
            if (rows.Length == 0)
            {
                ReportPanel.Controls.Clear();
                Hasan.CMessageBoxSmall.ShowBox("No record has been found, 
		to generate Reports", (int)Hasan.CMessageBox.Type.Exclamation, 
		Location.X, Location.Y);
                return;
            }

            // Set report's title
            this.chart.Titles.Add(SetTitle());

            // Initialize Series
            System.Windows.Forms.DataVisualization.Charting.Series series = 
		new System.Windows.Forms.DataVisualization.Charting.Series();
            series.ChartArea = "Default";
            series.Legend = "Default";
            series.Name = "series";
            series.XValueType = 
	     System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
            this.chart.Series.Clear();

            // Set title for Report
            this.chart.Series.Add(series);

            TimeSpan ts = DateTime.Now - new DateTime(1900, 1, 1);
            double days = ts.Days;
            double days2 = days;
            int amount = 0;

            // providing series with datapoints 
            for (int pointIndex = 0; pointIndex < rows.Length; pointIndex++)
            {
                amount = pseg.ProcessItem(pointIndex);
                ts = DateTime.Parse(rows[pointIndex]["Date"].ToString()) - 
						new DateTime(1900, 1, 1);
                series.Points.AddXY(ts.Days, amount);
            }
            series.Color = _serial_Color;
                       
            // Display margin on chart
            if (chkMargin.Checked)
                chart.ChartAreas["Default"].AxisX.IsMarginVisible = true;
            else
                chart.ChartAreas["Default"].AxisX.IsMarginVisible = false;

            // Display 3D chart
            if (this.chkDisplayBar3D.Checked)
            {
                series.BorderColor = System.Drawing.Color.Transparent;
                chart.ChartAreas["Default"].Area3DStyle.Enable3D = true;
            }
            else
            {
                series.BorderColor = System.Drawing.Color.Teal;
                chart.ChartAreas["Default"].Area3DStyle.Enable3D = false;
            }

            // Setting attribute associated with chart area
            chart.ChartAreas[0].AxisX.LabelStyle.IntervalOffset = 1;
            chart.ChartAreas[0].AxisX.LabelStyle.IntervalOffsetType = 
	    System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Days;
            chart.ChartAreas[0].AxisX.LabelStyle.Interval = 2;
            chart.ChartAreas[0].AxisX.LabelStyle.IntervalType = 
	     System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Days;
        }
        #endregion

w_s_c_bar.jpg

蜡烛图

蜡烛图用于监控一段时间内材料或成品的费率。可以通过以下代码建立此图表

#region Kagi Chart
        private void InitializeKagiChart()
        {
            // Initialize chart control
            this.chart = SetChart();

            // Suspend Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
            this.SuspendLayout();
            
            // Add Chart control to Panel
            this.ReportPanel.Controls.Add(this.chart);

            // populating the chart
            KagiChartTypeLoad();

            // Resume Chart Layout
            ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
            this.ResumeLayout(false);
        }
        private void KagiChartTypeLoad()
        {
            Main.ChartDialog.PlantSegregation pseg =
               new ISCMS.Main.ChartDialog.PlantSegregation
               (_plantSegment, _charts, _chartBy, _is_Segregation, this);

            rows = pseg.Process();

            if (rows.Length == 0)
            {
                ReportPanel.Controls.Clear();
                Hasan.CMessageBoxSmall.ShowBox("No record has been found, 
		to generate Reports", (int)Hasan.CMessageBox.Type.Exclamation, 
		Location.X, Location.Y);
                return;
            }  
            
            DataSet ds = new DataSet();
            ds.Merge(rows);
            System.Windows.Forms.DataVisualization.Charting.Series series = 
		new System.Windows.Forms.DataVisualization.Charting.Series();
            series.BorderColor = System.Drawing.Color.Teal;
            series.BorderWidth = 3;
            series.ChartArea = "Default";
            series.ChartType = 
	     System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Kagi;
            series.Color = System.Drawing.Color.Tomato;
            series.CustomProperties = "PriceUpColor=SkyBlue";
            series.IsXValueIndexed = true;
            series.Legend = "Default";
            series.Name = "Default";
            series.ShadowColor = System.Drawing.Color.Gainsboro;
            series.ShadowOffset = 2;
            series.XValueType = 
		System.Windows.Forms.DataVisualization.Charting.ChartValueType.Date;
            series.YValueType = 
		System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            this.chart.Titles.Add(SetTitle());

            series.Points.Clear();
            double bufRate = 0;
            TimeSpan ts;

            for (int pointIndex = 0; pointIndex < rows.Length; pointIndex++)
            {
                ts = DateTime.Parse(rows[pointIndex]["Date"].ToString()) - 
						new DateTime(1900, 1, 1);
                if (ds.Tables[0].Select(" Date = #" + 
	       DateTime.Parse(rows[pointIndex]["Date"].ToString()).ToShortDateString() 
		+ "#").Length > 0)// ts.Days == 0 )
                {
                    series.Points.AddXY(ts.Days, Convert.ToDouble(rows[pointIndex]
						["Unit_Cost"]));
                    bufRate = Convert.ToDouble(rows[pointIndex]["Unit_Cost"]);
                }
                else
                    series.Points.AddXY(ts.Days, bufRate);
            }
            series["ReversalAmount"] = combReversalAmount.Text;
            this.chart.Series.Add(series);
        }
        #endregion 

历史

  • 2009 年 10 月 8 日:首次发布
© . All rights reserved.