Advertisement
Guest User

Untitled

a guest
Mar 6th, 2013
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Text.RegularExpressions;
  10. using System.IO;
  11. using System.Windows.Forms.DataVisualization.Charting;
  12.  
  13. namespace Test_1
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         private Random _R = new Random();
  18.         Random rand = new Random();
  19.  
  20.         int cind = 0;
  21.         char[] arr = new char[] { 'a', 'b', 'c'};
  22.  
  23.         public Form1()
  24.         {
  25.             InitializeComponent();
  26.  
  27.         }
  28.  
  29.         private void button1_Click(object sender, EventArgs e)
  30.         {
  31.             var leg = CreateLegend();
  32.             chart1.Legends.Add(leg);
  33.             chart1.Series.Add(CreateSeries(leg));
  34.         }
  35.  
  36.         public Series CreateSeries(Legend legend)
  37.         {
  38.             var seriesDetail = new Series();
  39.             seriesDetail.Name = "Result Chart" + arr[cind++];
  40.             seriesDetail.IsValueShownAsLabel = false;
  41.             seriesDetail.ChartType = SeriesChartType.Pie;
  42.             seriesDetail.BorderWidth = 2;
  43.  
  44.             for (int i = 0; i < 10; i++)
  45.             {
  46.                 var p = seriesDetail.Points.Add(rand.NextDouble());
  47.                 p.LegendText = new string('x', i);
  48.                
  49.             }
  50.  
  51.             seriesDetail.ChartArea = "Result Chart";
  52.             seriesDetail.Legend = legend.Name;
  53.             return seriesDetail;
  54.         }
  55.  
  56.         public Legend CreateLegend()
  57.         {
  58.             var legend = new Legend();
  59.  
  60.             legend.Enabled = true;
  61.             legend.Font = new Font("Arial", 11F);
  62.             legend.ForeColor = Color.FromArgb(102, 102, 102);
  63.             legend.InsideChartArea = "Result Chart";
  64.  
  65.             legend.Position = new ElementPosition(65, 10, 30, 60);
  66.             legend.Name = string.Format("Legend No. {0}", cind);
  67.  
  68.             legend.LegendStyle = LegendStyle.Column;
  69.  
  70.             legend.CellColumns.Add(new LegendCellColumn() { ColumnType = LegendCellColumnType.SeriesSymbol });
  71.             legend.CellColumns.Add(new LegendCellColumn()
  72.             {
  73.                 ColumnType = LegendCellColumnType.Text,
  74.                 Alignment = ContentAlignment.MiddleLeft
  75.             });
  76.  
  77.             return legend;
  78.         }
  79.  
  80.         private void button2_Click(object sender, EventArgs e)
  81.         {
  82.             chart1.Series.Clear();
  83.             chart1.Legends.Clear();
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement