This question is locked. New answers and comments are not allowed.
Hai,
I'm creating a simple program to display some values in a chart. The user can select the type of chart.But I'm having problem to create the pie chart. The problem is that I cannot combine two values into a single pie.Instead only by creating two chartseries. Pls help me to rectify the problem.
Thanks
| using System; |
| using System.Collections.Generic; |
| using System.ComponentModel; |
| using System.Data; |
| using System.Drawing; |
| using System.Linq; |
| using System.Text; |
| using System.Windows.Forms; |
| using Telerik.Charting; |
| using Telerik.WinControls.UI; |
| using Telerik.WinControls; |
| using Telerik.WinControls.Primitives; |
| using FrmErdStatusChart.CallSignWebService; |
| using System.Collections; |
| namespace FrmErdStatusChart |
| { |
| public partial class Form1 : RadForm |
| { |
| public Form1() |
| { |
| InitializeComponent(); |
| radChart1.ChartTitle.TextBlock.Text = "Status Chart"; |
| radChart1.Appearance.Border.Visible = false; |
| radChart1.Appearance.FillStyle.MainColor = Color.Lavender; |
| radChart1.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.Black; |
| this.radChart1.Series[0].Appearance.LegendDisplayMode = Telerik.Charting.ChartSeriesLegendDisplayMode.Nothing; |
| this.radChart1.Series[1].Appearance.LegendDisplayMode = Telerik.Charting.ChartSeriesLegendDisplayMode.Nothing; |
| } |
| CallSignWebService.CallSignWebService callsignWS = new CallSignWebService.CallSignWebService(); |
| ArrayList statusArray = new ArrayList(); |
| ChartSeries cs = new ChartSeries(); |
| ChartSeries cs1 = new ChartSeries(); |
| int online ; |
| int offline ; |
| string[] status = {"online" , "offline" }; |
| //Add the status ==> online |
| public void AddAvailable() |
| { |
| cs.Clear(); |
| cs.Items.Add(new ChartSeriesItem(online)); |
| radChart1.Series.Add(cs); |
| cs.Name = "Online " + online; |
| radChart1.DataBind(); |
| } |
| //Add status ==> offline |
| public void AddOffline() |
| { |
| cs1.Clear(); |
| cs1.Items.Add(new ChartSeriesItem(offline)); |
| radChart1.Series.Add(cs1); |
| cs1.Name = "offline "+offline; |
| radChart1.DataBind(); |
| } |
| //Get the status from the callsign |
| public void addStatus() |
| { |
| callSign[] callSignList = callsignWS.findAll(); |
| foreach (callSign callSign in callSignList) |
| { |
| statusArray.Add(callSign.status); |
| ///// Console.WriteLine(callSign.unit); |
| } |
| } |
| //filter out the status according to online,offline |
| public void addChart() |
| { |
| online = 0; |
| offline = 0; |
| /* for (int i = 0; i < statusArray.Count; i++) |
| { |
| //counts status ==> online |
| foreach (string online in statusArray) |
| { |
| o++; |
| } |
| //counts status ==> offline |
| foreach (string offline in statusArray) |
| { |
| f++; |
| } |
| break; |
| }*/ |
| for (int i = 0; i < statusArray.Count;i++ ) |
| { |
| if (statusArray[i].ToString() == "Online") |
| { |
| online++; |
| } |
| else offline++; |
| } |
| Console.WriteLine("Online ==> "+online); |
| Console.WriteLine("Offline ==> "+offline); |
| } |
| private void radComboBox1_SelectedValueChanged(object sender, EventArgs e) |
| { |
| } |
| private void radComboBox1_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| // Check whether an item in combo box is selected |
| if (radComboBox1.SelectedItem != null) |
| { |
| //value is equal to pie |
| if (radComboBox1.SelectedIndex == 0) |
| { |
| /* radChart1.Series.Clear(); |
| ChartSeries cs2 = new ChartSeries(); |
| cs2.Type = ChartSeriesType.Pie; |
| radChart1.Series.Add(cs2); |
| radChart1.DataSource = new int[] {o,f }; |
| radChart1.DataBind();*/ |
| AddOffline(); |
| AddAvailable(); |
| cs.Type = ChartSeriesType.Pie; |
| cs1.Type = ChartSeriesType.Pie; |
| } |
| //value is equal to bar |
| else if (radComboBox1.SelectedIndex == 1) |
| { |
| AddOffline(); |
| AddAvailable(); |
| cs.Type = ChartSeriesType.Bar; |
| cs1.Type = ChartSeriesType.Bar; |
| } |
| //Value is equal to point |
| else if (radComboBox1.SelectedIndex == 2) |
| { |
| AddOffline(); |
| AddAvailable(); |
| cs.Type = ChartSeriesType.Point; |
| cs1.Type = ChartSeriesType.Point; |
| } |
| } |
| } |
| private void Form1_Load(object sender, EventArgs e) |
| { |
| addStatus(); |
| addChart(); |
| } |
| } |
| } |