Monday, August 4, 2014

Dot Net Chart Control

http://www.codeproject.com/Articles/802845/Pareto-Chart-Csharp

Uses GDI calls to make a charting control for .net


Pareto Chart C#

31 Jul 2014
Pareto Chart Control Using C#


Introduction

The main aim of this article is to create a simple Pareto Chart Control .There is few Third party Pareto charts available and also pareto chart can be made using MS Chart controls.My aim is to creata a simple pareto Chart User control.As a result ,Yes i have created a Pareto Chart user control using C#.Net.First we start with what is Pareto chart.
Pareto Chart
Pareto Chart is a combination of both Bar graph and Line graph. In Pareto chart X-Axis we will plot the Data Names. In Left Y-Axis we will plot the Data Frequency and in Right side Y-Axis we will plot the Data Cumulative Frequency Percentage.A pareto chart is used to graphically summarize and display the relative importance of the differences between groups of data.
The rules of Pareto chart are to start displaying highest to lowest Frequency data as bar graph. Display the Cumulative Frequency Percentage data as a Line Graph.
here we can see a Sample data.
S.No Name Freq Cum Freq Cum Per %
1 Pareto1 53 53       19.27272727
2 pareto2 45 98       35.63636364
3 pareto3 43 141       51.27272727
4 pareto4 37 178       64.72727273
5 pareto5 35 213       77.45454545
6 pareto6 27 240       87.27272727
7 pareto7 23 263       95.63636364
8 pareto8 12 275       100
 Sum 275  
 

The Above sample data has been used in my program to display the result of the Pareto chart. From the above data we can see.
Fre(Frequency 

<blah>

1) First we will start with the User Control .To Create a user control .
  1. Create a new Windows Control Library project.
  2. Set the Name of Project and Click Ok(here my user control name is ShanuParetoChart_CTL).
  3. Add all the controls which is needed.
  4. In code behind declare all the public variables and Public property variables.
 private System.Windows.Forms.PictureBox PicBox;
        private System.Windows.Forms.Panel OuterPanel;
        private System.ComponentModel.Container components = null;
        private string m_sPicName = "";
        ContextMenuStrip docmenu = new System.Windows.Forms.ContextMenuStrip();
        ToolStripMenuItem saveimg = new ToolStripMenuItem();

        int NoofPlots = 5;

        public DataTable dt = new DataTable();

        Font f12 = new Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel);
        Pen B1pen = new Pen(Color.Black, 1);
        Pen B2pen = new Pen(Color.Black, 2);
       

       int[] intDataValue;
        int[] intCumulativeValue;
        Double[] intCumulativeValuePer;
        Double[] XaxisplotWidth;

        int First_chartDatarectHeight = 400;
        int First_chartDatarectWidth = 600;
        Font f10 = new Font("arial", 10, FontStyle.Bold, GraphicsUnit.Pixel);
        LinearGradientBrush a2 = new LinearGradientBrush(new RectangleF(0, 0, 100, 19), Color.DarkGreen, Color.Green, LinearGradientMode.Horizontal);
        LinearGradientBrush a3 = new LinearGradientBrush(new RectangleF(0, 0, 100, 19), Color.DarkRed, Color.Red, LinearGradientMode.Horizontal);
        LinearGradientBrush a1 = new LinearGradientBrush(new RectangleF(0, 0, 100, 19), Color.Blue, Color.DarkBlue, LinearGradientMode.Horizontal);
5.In Pictuerbox Paint Method I call a Method to draw the pareto chart.i have used .NET GDI+ to Draw both Bar and Line Graph in Pareto chart with the Datatable result.In paint method i check for the Datatable Data and store the Frequency ,Cumulative Frequency and Cumulative Frequency Percentage to a Array.
<see main link at top>

No comments:

Post a Comment