Using System; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Text; Using System.Windows.Forms; Using Devexpress.xtracharts;
namespace Chartcontrol {public partial class Form1:form {public Form1 () {Initiali Zecomponent (); }
private dictionary<string, double> chartpiedatadic = new Dictionary <string, double> (); private dictionary<string, double> chartbardatadic = new Dictionary <string, double> (); private void Form1_Load (object sender, EventArgs e) { Combobox1.selectedindex = 0; Initpiechartdata (); Initbarchartdata (); Showpie (); } private void Showpie () {charttitle title = new ChartTitle (); Title. Text = "Provincial Traffic Analysis pie chart-traffic type distribution";
ChartControl1.Titles.Clear (); CHARTCONTROL1.TITLES.ADD (title);
Series Series1 = new series ("Traffic Type", Viewtype.pie); ((piepointoptions) series1. pointoptions). Pointview = pointview.argumentandvalues;
foreach (keyvaluepair<string, double> keyvalue in Chartpiedatadic) {series1. Points.Add (New Seriespoint (keyvalue. Key, new double[] {keyvalue. Value})); }
chartcontrol1.series.clear (); ChartControl1.Series.Add (series1); } private void Initpiechartdata () { try { Chartpiedatadic.add ("Dalian", 0.2); Chartpiedatadic.add ( "Shenyang", 0.26); Chartpiedatadic.add ( "Jinzhou", 0.15); Chartpiedatadic.add ( "Panjin", 0.15); Chartpiedatadic.add ("Benxi", 0.1); Chartpiedatadic.add ( "Fushun", 0.12); Chartpiedatadic.add ( "Yingkou", 0.02); } catch {} } private void Initbarchartdata () { try { Chartbardatadic.add ( "2001", 0.05); Chartbardatadic.add ( "2002 ", 0.02); Chartbardatadic.add ( "2003", 0.08); Chartbardatadic.add ( "2004", 0.15); Chartbardatadic.add ( "2005", 0.1); Chartbardatadic.add ( "2006", 0.3); Chartbardatadic.add ( "2007", 0.2); Chartbardatadic.add ( "2008", 0.1); } catch {} } PRivate void ComboBox1_SelectedIndexChanged (object sender, EventArgs e) { if (comboBox1.Text.IndexOf ("pie chart")! =-1) { Showpie (); } Else if (comboBox1.Text.IndexOf ("bar chart")! =-1) { Showbar (); } Else if (comboBox1.Text.IndexOf ("line chart")! =-1) { ShowLine (); } Else if (comboBox1.Text.IndexOf ("dot graph")! =-1) { Showpoint (); } }
private void Showbar () {try {charttitle title = new ChartTitle (); Title. Text = "The statistical analysis of the growth rate of the urban network element";
ChartControl1.Titles.Clear (); CHARTCONTROL1.TITLES.ADD (title);
Series Series2 = new Series ("Dalian", Viewtype.bar); Series series3 = new Series ("Shenyang", Viewtype.bar); Series series4 = new Series ("Benxi", Viewtype.bar); foreach (KeyValuePair <string, double> kvp in Chartbardatadic) { Series2. Points.Add (New Seriespoint (KVP. Key, new double[] {kvp. Value})); Series3. Points.Add (New SerIespoint (KVP. Key, new double[] {kvp. Value + 0.08}); SERIES4. Points.Add (New Seriespoint (KVP. Key, new double[] {kvp. Value + 0.02}); }
ChartControl1.Series.Clear (); CHARTCONTROL1.SERIES.ADD (Series2); CHARTCONTROL1.SERIES.ADD (SERIES3); CHARTCONTROL1.SERIES.ADD (SERIES4);
chartControl1.Legend.Visible = true;//Display label (next to the label which color represents which city)} catch {}}
private void ShowLine () {charttitle title = new ChartTitle (); Title. Text = "line graph"; ChartControl1.Titles.Clear (); CHARTCONTROL1.TITLES.ADD (title);
Series Series1 = new series ("Liaoning", Viewtype.line); Series1. Argumentscaletype = scaletype.numerical;
series1. Points.Add (New Seriespoint (1, new double[] {10})); series1. Points.Add (New Seriespoint (2, new double[] {12})); series1. Points.Add (New Seriespoint (3, new double[] {14})); series1. Points.Add (New Seriespoint (4, new double[] {17})); series1. Points.Add (New Seriespoint (5, new double[] {21})); series1. Points.Add (New Seriespoint (6, new double[] {26})); series1. Points.Add (New Seriespoint (7, new double[] {29})); series1. Points.Add (New Seriespoint (8, New double[] {30});
((Pointseriesview) series1. View). Pointmarkeroptions.kind = Markerkind.triangle;
Series Series2 = new series ("Shandong", Viewtype.line); series2. Argumentscaletype = scaletype.numerical; This sentence must have, otherwise the dot cannot draw out. ((Lineseriesview) Series2. View). Linestyle.dashstyle = Dashstyle.dashdotdot; Series2. Points.Add (New Seriespoint (1, new double[] {4})); Series2. Points.Add (New Seriespoint (2, new double[] {14})); Series2. Points.Add (New Seriespoint (3, new double[] {17})); Series2. Points.Add (New Seriespoint (4, new double[] {22})); Series2. Points.Add (New Seriespoint (5, new double[] {20})); Series2. Points.Add (New Seriespoint (6, new double[] {15})); Series2. Points.Add (New Seriespoint (7, new double[] {18})); Series2. Points.Add (New Seriespoint (8, new double[] {11}));
((Pointseriesview) Series2. View). Pointmarkeroptions.kind = Markerkind.cross;
ChartControl1.Series.Clear (); CHARTCONTROL1.SERIES.ADD (SERIES1); CHARTCONTROL1.SERIES.ADD (Series2); ChartControl1.Legend.Visible = true; }private void Showpoint () {charttitle title = new ChartTitle (); Title. Text = "point graph"; ChartControl1.Titles.Clear (); CHARTCONTROL1.TITLES.ADD (title);
Series Series1 = new Series ("Number of people on the line", Viewtype.point); Series1. Argumentscaletype = scaletype.numerical;
series1. Points.Add (New Seriespoint (1, new double[] {20})); series1. Points.Add (New Seriespoint (2, new double[] {12})); series1. Points.Add (New Seriespoint (3, new double[] {11})); series1. Points.Add (New Seriespoint (4, new double[] {17})); series1. Points.Add (New Seriespoint (5, new double[] {21})); series1. Points.Add (New Seriespoint (6, new double[] {21})); series1. Points.Add (New Seriespoint (7, new double[] {29})); series1. Points.Add (New Seriespoint (8, New double[] {30});
((Pointseriesview) series1. View). Pointmarkeroptions.kind = Markerkind.triangle;
Series Series2 = new Series ("Number of downline", viewtype.point); Series2. Argumentscaletype = scaletype.numerical; This sentence must have, otherwise the dot cannot draw out.
Series2. Points.Add (New Seriespoint (1, new double[] {4})); Series2. Points.Add (New Seriespoint (2, new double[] {14})); Series2. Points.Add (New Seriespoint (3, new double[] {17})); Series2. Points.Add (New Seriespoint (4, new double[] {22})); Series2. Points.Add (New Seriespoint (5, new double[] {20})); Series2. Points.Add (New Seriespoint (6, new double[] {15})); Series2. Points.Add (New Seriespoint (7, new double[] {18})); Series2. Points.Add (New Seriespoint (8,New double[] {11});
((Pointseriesview) Series2. View). Pointmarkeroptions.kind = Markerkind.cross;
ChartControl1.Series.Clear (); CHARTCONTROL1.SERIES.ADD (SERIES1); CHARTCONTROL1.SERIES.ADD (Series2); ChartControl1.Legend.Visible = true; } } }
DevExpress.XtraCharts.chartControl