Chart.` The Chart control visualizes your data. It displays data in your Windows Forms program as a bar graph or chart. With Chart you can quickly display your data in a colorful graphic controlled by C# code.`390`First,` you must be using a newer version of the .NET Framework. Older versions will not have the Chart control available. Please open the Toolbox and drag the Chart item to the Form. `Next: `Select Properties after right-clicking on the Chart. You can add Series and Titles this way.`For our example, remove the default Series1 that was added by Visual Studio.`Example.` Now we can use the Chart. In the next step, we will use the Form1_Load event handler to initialize the Chart we just added. To add Form1_Load, double-click on the Form window in Visual Studio.`In Form1_Load,` we assign an array of strings (Series) and an array of integers (Points). In the for-loop, we add the strings to the Series collection and add the integers to the Points collections on those Series. `For `for`The loop results in two Series: a Cats series with a Point of 1, and a Dogs series with a Point of 2.`Info: `These are reflected in a bar graph, which is shown in this page's screenshot.`When you call Series.Add,` you can pass a string which becomes the name of the Series. A Series object is returned by Add. Then you can assign a local variable to the result of Add and access the Points collection on the Series. `By calling Points.Add, you can set the values. We pass in elements from our array.`Palette.` Some computer programmers may not be artistically inclined. The Palette property on the Chart type can help with this. You can use a ChartColorPalette enumerated constant in an assignment expression.`Image.` Sometimes you will need to save your chart to an image file. The SaveImage method takes the graphical representation of your chart as it appears on the screen and writes it to a file or Stream you specify. `In the above example, try adding this statement and then check out the chart.png file.`Summary.` We looked at the Chart type in the Windows Forms library. With Chart, you can automatically generate graphs based on data. These bar graphs can then be used in a variety of places or displayed directly in a Windows Forms program.

345E4Q that sets Chart control up: C#5 4P4O; 4P4O.Windows.Forms; 4P4O.Windows.Forms.DataVisualization.Charting4Snamespace WindowsFormsApplication1 { 34=partial 4DForm1 : Form 3{ 334=Form1() 33{4'InitializeComponent(); 33} 334: 4fForm1_Load(object sender, EventArgs e) 33{54'4{Data 4Ts.4'54L[] series4U4z{ "Cats", "Dogs" };4'4}[] po4}s4U4z{ 1, 2 };5 4'4{Set palette.4'5this.chart1.Palette4zChartColorPalette.SeaGreen;5 4'4{Set title.4'5this.chart1.Titles.4n"Pets");5 4'4{Add series.4'54o(4si4z0; i < series4U.L4Z; i++)4'{54'34{Add series.4'35Series series4zthis.chart1.Series.4nseries4U[i]);5 4'34{Add po4}.4'35series.Po4}s.4npo4}s4U[i]);4'} 33} 3} }5Code that saves chart4limage: C#5 this.chart1.SaveImage("C:\\chart.png", ChartImageFormat.Png);5