Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, I'm kind of new to charts and am trying this for the first time.

I am trying to implement multiple series within the same chart. I have two listboxes that keeps track of the order as well as which ones are shown (a shown listbox and a hidden listbox). I am storing the list of series as a session variable as List<series>. When I graph the chart I cycle through the listbox and find the name of the series that are in the shown listbox, then add them to the chart.

This all works fine. I can even remove a series (aka hide it by moving it to the hide listbox). I have tried both chart.Series.Clear() //which through debugging shows the charts series being cleared, as well as foreaching through all the charts series and series.remove(chart.Series.FindByName(item.Value)) which also works in finding the series and removing it.

BUT when I try to re-add a series that already existed before, it crashes. Is there something else I have to clear? The only time I am able to add something I added before is when I clear the session list that has all the series.

I'm guessing it has something to do with the name of the series being the same, but I feel like that shouldn't matter since I clear the charts series. The other problem might have to be with me storing the series as a sessionstateVar. It works fine but I think for some reason it may be the reason why I can't re-add a series to the same name.

Any help would be greatly needed and appreciated.

Here is the crash
Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   System.Web.UI.DataVisualization.Charting.Series.ResetAutoValues(Boolean reset) +446
   System.Web.UI.DataVisualization.Charting.Series.ResetAutoValues() +34
   System.Web.UI.DataVisualization.Charting.Chart.ResetAutoValues() +128
   System.Web.UI.DataVisualization.Charting.ChartSerializer.Save(TextWriter writer) +162
   System.Web.UI.DataVisualization.Charting.Chart.SaveViewState() +345
   System.Web.UI.Control.SaveViewStateRecursive() +187
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Control.SaveViewStateRecursive() +106
   System.Web.UI.Page.SaveAllState() +168
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1099
Posted

Sorry for the bump. Anybody have experience with charts? I imagine it must be a semi-common problem with them (adding then removing then adding the same series) yet I haven't found any other topics about it. Kind of puts my project to a hault until I fix it.
 
Share this answer
 
Check this was my method for char if that can help you

public void SelectIncomeVSExpense(DataTable dtGetInfo)
    {
        divErrIncomevsExpense.Visible = false;
        divErrIncomevsExpense.InnerHtml = "";
        divIncomeVsExpense.Visible = true;
        //Used For the Legend (Start here)
        chartIncomeVsExpense.Legends["Default"].Docking = Docking.Bottom;
        chartIncomeVsExpense.Legends["Default"].Alignment = System.Drawing.StringAlignment.Center;
        chartIncomeVsExpense.Legends["Default"].LegendStyle = LegendStyle.Table;
        chartIncomeVsExpense.Legends["Default"].TableStyle = LegendTableStyle.Wide;
        chartIncomeVsExpense.Legends["Default"].Font = new Font("Verdana", 8, FontStyle.Regular);
        chartIncomeVsExpense.Legends["Default"].ForeColor = Color.Black;
        //Used For the Legend (End here)
        string seriesname = string.Empty;
        string SERIESEXPENSE = string.Empty;
        string SeriesRefund = string.Empty;

        seriesname = "Income";
        SERIESEXPENSE = "Expenses";
        SeriesRefund = "Refund";

        string strCurrencyType = dtGetInfo.Rows[0]["Currency"].ToString();
        //if there are more than one lgends like in BP we have to create two Series
        // Series is the collection of data that we have to show on chart
        chartIncomeVsExpense.Series.Add(seriesname);
        chartIncomeVsExpense.Series[seriesname].ChartType = SeriesChartType.Column;//(SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlChartType.SelectedItem.Text, true);
        chartIncomeVsExpense.Series[seriesname]["PointWidth"] = "0.4";
        chartIncomeVsExpense.Series[seriesname].Name = seriesname;
        chartIncomeVsExpense.Series[seriesname].IsValueShownAsLabel = true;
        chartIncomeVsExpense.Series[seriesname].Label = "" + strCurrencyType + "#VAL ";

        chartIncomeVsExpense.Series.Add(SERIESEXPENSE);
        chartIncomeVsExpense.Series[SERIESEXPENSE].ChartType = SeriesChartType.Column;//(SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlChartType.SelectedItem.Text, true);        
        chartIncomeVsExpense.Series[SERIESEXPENSE]["PointWidth"] = "0.4";
        chartIncomeVsExpense.Series[SERIESEXPENSE].Name = SERIESEXPENSE;
        chartIncomeVsExpense.Series[SERIESEXPENSE].IsValueShownAsLabel = true;
        chartIncomeVsExpense.Series[SERIESEXPENSE].Label = "" + strCurrencyType + "#VAL ";

        chartIncomeVsExpense.Series.Add(SeriesRefund);
        chartIncomeVsExpense.Series[SeriesRefund].ChartType = SeriesChartType.Column;//(SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlChartType.SelectedItem.Text, true);        
        chartIncomeVsExpense.Series[SeriesRefund]["PointWidth"] = "0.4";
        chartIncomeVsExpense.Series[SeriesRefund].Name = SeriesRefund;
        chartIncomeVsExpense.Series[SeriesRefund].IsValueShownAsLabel = true;
        chartIncomeVsExpense.Series[SeriesRefund].Label = "" + strCurrencyType + "#VAL ";


        chartIncomeVsExpense.ChartAreas["ChartArea1"].Position.Auto = false;
        chartIncomeVsExpense.ChartAreas["ChartArea1"].Position.X = 5;
        chartIncomeVsExpense.ChartAreas["ChartArea1"].Position.Y = 15;
        chartIncomeVsExpense.ChartAreas["ChartArea1"].Position.Width = 90;
        chartIncomeVsExpense.ChartAreas["ChartArea1"].Position.Height = 60;
        chartIncomeVsExpense.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsStaggered = false;
        chartIncomeVsExpense.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = true;
        chartIncomeVsExpense.ChartAreas["ChartArea1"].AxisX.LabelStyle.Angle = 0;




        Title t = new Title("Income vs Expenses", Docking.Top, new System.Drawing.Font("Verdana", 14, System.Drawing.FontStyle.Regular), Color.FromArgb(28, 29, 29));
        chartIncomeVsExpense.Titles.Add(t);
        string strQuery = String.Empty;
        strQuery = "IsAllowedViewEarning=1 ";
        DataView dv5 = new DataView(dtGetInfo);
        dv5.RowFilter = strQuery;
        DataView dv6 = new DataView(dtGetInfo);
        chartIncomeVsExpense.Series[seriesname].Points.DataBindXY(dv5, "FullName", dv5, "TotalEarning");
        chartIncomeVsExpense.Series[SERIESEXPENSE].Points.DataBindXY(dv6, "FullName", dv6, "TotalExpenses");
        chartIncomeVsExpense.Series[SeriesRefund].Points.DataBindXY(dv6, "FullName", dv6, "Refund");

        chartIncomeVsExpense.Series[SERIESEXPENSE].Legend.Remove(0, chartIncomeVsExpense.Series[SERIESEXPENSE].Legend.Length - 1);
    }
 
Share this answer
 
Comments
Anuja Pawar Indore 8-Sep-11 9:22am    
I have worked on ASP.NET chart control, if you can share your code then i might help you
MJ_ 8-Sep-11 10:28am    
Here is the code for the control that has the graph
///
/// Public ctrl graph class
///

public partial class CtrlBarGraph : System.Web.UI.UserControl
{
private SessionStateVar<busadvertisingcollection> m_AdvertisingCollection;
private SessionStateVar<busregioncollection> m_RegionCollection;
private SessionStateVar<List<series>> m_seriesCollection;
///
/// CtrlBarGraph shows any type of bar graph
///

public CtrlBarGraph()
{
m_AdvertisingCollection = new SessionStateVar<busadvertisingcollection>("advertisingCollection");
m_RegionCollection = new SessionStateVar<busregioncollection>("regionCollection");
m_seriesCollection = new SessionStateVar<List<series>>("seriesCollection", new List<series>());

}
protected void Page_Init(object sender, EventArgs e)
{
chrAdvertising.EnableViewState = true;
}
///
/// Page load event
///

/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
//if (chrAdvertising.Series.Count == 0)
// chrAdvertising.Visible = false;
chrAdvertising.ViewStateContent = SerializationContents.Default;
lblError.Visible = false;
int i = 0;
while (i < ddlColorPicker.Items.Count)
{
ddlColorPicker.Items[i].Attributes.Add("style", "background-color:" + ddlColorPicker.Items[i].Value);
i++;
}
}
///
/// ibClicked happens when any image button is clicked.
/// Moves the listitems in the list box either up or down,
/// or moves them between shown and hidden
///

/// <param name="sender"></param>
/// <param name="e"></param>
protected void ibClicked(object sender, EventArgs e)
{
ImageButton ibClicked = sender as ImageButton;
string command = ibClicked.CommandArgument;
if (command == "up")
lbSeriesCurrent.Items.ShiftSelectedUp();
else if (command == "down")
lbSeriesCurrent.Items.ShiftSelectedDown();
else if (command == "hide")
{
foreach (ListItem item in lbSeriesCurrent.Items.GetAllSelected())
{
chrAdvertising.Series.Remove(chrAdvertising.Series.FindByName(item.Value));
}
lbSeriesCurrent.Items.MoveSelectedTo(lbSeriesNotShown.Items, true);
}
else if (command == "show")
lbSeriesNotShown.Items.MoveSelectedTo(lbSeriesCurrent.Items, true);
showGraph();
}
///
/// populates the advertising collection off the session variable
///

protected void populate()
{
if (!m_AdvertisingCollection.IsSet())
{
m_AdvertisingCollection.Value = BusAdvertisingManager.GetALL("DateCreated");
}
}
///
/// Populates the regions from the session variable
///

protected void populateRegions()
{
if (!m_RegionCollection.IsSet())
{
m_RegionCollection.Value = BusRegionManager.GetRegionAll();
}
}
///
/// Appends the current search to the list box
///

/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAppend_Click(object sender, EventArgs e)
{

string legend = getLegendName();
ListItem liAdded = new ListItem();
liAdded.Text = legend;
l
MJ_ 8-Sep-11 10:47am    
It wont let me reply with the entire code and it wont let me post the code either. So here is the important parts, everything else works fine.
//btnAppend happens when you first add a series to the listbox. It then
protected void btnAppend_Click(object sender, EventArgs e)
{

string legend = getLegendName();
ListItem liAdded = new ListItem();
liAdded.Text = legend;
liAdded.Value = legend;
foreach (ListItem item in lbSeriesCurrent.Items)
{
if (item.Text == liAdded.Text)
{
lblError.Visible = true;
return;
}
}
foreach (ListItem item in lbSeriesNotShown.Items)
{
if (item.Text == liAdded.Text)
{
lblError.Visible = true;
return;
}
}

populate();
Series addSeries = new Series(legend);
addSeries.ChartType = GetChartType();
addSeries.BorderWidth = 3;
addSeries.ShadowOffset = 2;

DateTime startDtm = tbDateBegin.Text.ToDateTime(m_AdvertisingCollection.Value[0].DateCreated);
DateTime EndDtm = tbDateEnd.Text.ToDateTime(m_AdvertisingCollection.Value.Last().DateCreated);
List<datetime> Periods = new List<datetime>();
List<List<double>> ListCollection = GetDateRange(startDtm, EndDtm, Periods);
List<double> Pages = new List<double>();
int count = 0;
BusAdvertisingCollection AdCollection = m_AdvertisingCollection.Value;

foreach (BusAdvertising item in AdCollection)
{
count = 0;
double itemGraphed = 0;
if (ddlSearchBy.SelectedItem.Value == "NumOfPieces")
itemGraphed = 1;
else if (ddlSearchBy.SelectedItem.Value == "NumOfPages")
itemGraphed = item.NumberOfPages;
else if (ddlSearchBy.SelectedItem.Value == "ComplexityScore")
itemGraphed = item.PageScoreID;
else if (ddlSearchBy.SelectedItem.Value == "TurnaroundTime")
itemGraphed = 1;////////TEMP, not working yet////////////////////////<----------FIX
if (!belongs(item, startDtm, EndDtm))
continue;
if (count + 1 > Periods.Count())
{
//count of 0, no items added within range
}
else if (count + 1 == Periods.Count())
{
//All datapoints fall within one time period
ListCollection[count].Add(itemGraphed);
}
else
{
//Item falls between two ranges of periods
while (count < Periods.Count && item.DateCreated >= Periods[count])
{
count++;
}
ListCollection[count - 1].Add(itemGraphed);
}
}
count = 0;
foreach (List<double> value in ListCollection)
{
string dateAxis = string.Empty;
if (Periods.Count == 1)
dateAxis = startDtm.ToShortDateString() + " - " + EndDtm.AddDays(-1).ToShortDateString();
else if ((count + 1 < Periods.Count))
dateAxis = Periods[count].ToShortDateString() + " - " + Periods[count + 1].AddDays(-1).ToShortDateString();
else
dateAxis = Periods[count].ToShortDateString() + " - " + EndDtm.ToShortDateString();
if (value.Count == 0)
addSeries.Points.AddXY(dateAxis, 0);
else if (cbAvg.Checked)
addSeries.Points.AddXY(dateAxis, value.Average());
else
XML
/// <summary>
    /// Public ctrl graph class
    /// </summary>
    public partial class CtrlBarGraph : System.Web.UI.UserControl
    {
        private SessionStateVar<BusAdvertisingCollection> m_AdvertisingCollection;
        private SessionStateVar<BusRegionCollection> m_RegionCollection;
        private SessionStateVar<List<Series>> m_seriesCollection;
        /// <summary>
        /// CtrlBarGraph shows any type of bar graph
        /// </summary>
        public CtrlBarGraph()
        {
            m_AdvertisingCollection = new SessionStateVar<BusAdvertisingCollection>("advertisingCollection");
            m_RegionCollection = new SessionStateVar<BusRegionCollection>("regionCollection");
            m_seriesCollection = new SessionStateVar<List<Series>>("seriesCollection", new List<Series>());

        }
        protected void Page_Init(object sender, EventArgs e)
        {
            chrAdvertising.EnableViewState = true;
        }
        /// <summary>
        /// Page load event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (chrAdvertising.Series.Count == 0)
            //    chrAdvertising.Visible = false;
            chrAdvertising.ViewStateContent = SerializationContents.Default;
            lblError.Visible = false;
            int i = 0;
            while (i < ddlColorPicker.Items.Count)
            {
                ddlColorPicker.Items[i].Attributes.Add("style", "background-color:" + ddlColorPicker.Items[i].Value);
                i++;
            }
        }        /// <summary>
        /// ibClicked happens when any image button is clicked.
        /// Moves the listitems in the list box either up or down,
        /// or moves them between shown and hidden
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ibClicked(object sender, EventArgs e)
        {
            ImageButton ibClicked = sender as ImageButton;
            string command = ibClicked.CommandArgument;
            if (command == "up")
                lbSeriesCurrent.Items.ShiftSelectedUp();
            else if (command == "down")
                lbSeriesCurrent.Items.ShiftSelectedDown();
            else if (command == "hide")
            {
                foreach (ListItem item in lbSeriesCurrent.Items.GetAllSelected())
                {
                    chrAdvertising.Series.Remove(chrAdvertising.Series.FindByName(item.Value));
                }
                lbSeriesCurrent.Items.MoveSelectedTo(lbSeriesNotShown.Items, true);
            }
            else if (command == "show")
                lbSeriesNotShown.Items.MoveSelectedTo(lbSeriesCurrent.Items, true);
            showGraph();
        }
        /// <summary>
        /// populates the advertising collection off the session variable
        /// </summary>
        protected void populate()
        {
            if (!m_AdvertisingCollection.IsSet())
            {
                m_AdvertisingCollection.Value = BusAdvertisingManager.GetALL("DateCreated");
            }
        }
        /// <summary>
        /// Populates the regions from the session variable
        /// </summary>
        protected void populateRegions()
        {
            if (!m_RegionCollection.IsSet())
            {
                m_RegionCollection.Value = BusRegionManager.GetRegionAll();
            }
        }
        /// <summary>
        /// Appends the current search to the list box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAppend_Click(object sender, EventArgs e)
        {

            string legend = getLegendName();
            ListItem liAdded = new ListItem();
            liAdded.Text = legend;
            liAdded.Value = legend;
            foreach (ListItem item in lbSeriesCurrent.Items)
            {
                if (item.Text == liAdded.Text)
                {
                    lblError.Visible = true;
                    return;
                }
            }
            foreach (ListItem item in lbSeriesNotShown.Items)
            {
                if (item.Text == liAdded.Text)
                {
                    lblError.Visible = true;
                    return;
                }
            }

            populate();
            Series addSeries = new Series(legend);
            addSeries.ChartType = GetChartType();
            addSeries.BorderWidth = 3;
            addSeries.ShadowOffset = 2;

            DateTime startDtm = tbDateBegin.Text.ToDateTime(m_AdvertisingCollection.Value[0].DateCreated);
            DateTime EndDtm = tbDateEnd.Text.ToDateTime(m_AdvertisingCollection.Value.Last().DateCreated);
            List<DateTime> Periods = new List<DateTime>();
            List<List<double>> ListCollection = GetDateRange(startDtm, EndDtm, Periods);
            List<double> Pages = new List<double>();
            int count = 0;
            BusAdvertisingCollection AdCollection = m_AdvertisingCollection.Value;

            foreach (BusAdvertising item in AdCollection)
            {
                count = 0;
                double itemGraphed = 0;
                if (ddlSearchBy.SelectedItem.Value == "NumOfPieces")
                    itemGraphed = 1;
                else if (ddlSearchBy.SelectedItem.Value == "NumOfPages")
                    itemGraphed = item.NumberOfPages;
                else if (ddlSearchBy.SelectedItem.Value == "ComplexityScore")
                    itemGraphed = item.PageScoreID;
                else if (ddlSearchBy.SelectedItem.Value == "TurnaroundTime")
                    itemGraphed = 1;////////TEMP, not working yet////////////////////////<----------FIX
                if (!belongs(item, startDtm, EndDtm))
                    continue;
                if (count + 1 > Periods.Count())
                {
                    //count of 0, no items added within range
                }
                else if (count + 1 == Periods.Count())
                {
                    //All datapoints fall within one time period
                    ListCollection[count].Add(itemGraphed);
                }
                else
                {
                    //Item falls between two ranges of periods
                    while (count < Periods.Count && item.DateCreated >= Periods[count])
                    {
                        count++;
                    }
                    ListCollection[count - 1].Add(itemGraphed);
                }
            }
            count = 0;
            foreach (List<double> value in ListCollection)
            {
                string dateAxis = string.Empty;
                if (Periods.Count == 1)
                    dateAxis = startDtm.ToShortDateString() + " - " + EndDtm.AddDays(-1).ToShortDateString();
                else if ((count + 1 < Periods.Count))
                    dateAxis = Periods[count].ToShortDateString() + " - " + Periods[count + 1].AddDays(-1).ToShortDateString();
                else
                    dateAxis = Periods[count].ToShortDateString() + " - " + EndDtm.ToShortDateString();
                if (value.Count == 0)
                    addSeries.Points.AddXY(dateAxis, 0);
                else if (cbAvg.Checked)
                    addSeries.Points.AddXY(dateAxis, value.Average());
                else
                    addSeries.Points.AddXY(dateAxis, value.Sum());
                count++;
            }
            addSeries.Color = System.Drawing.Color.FromName(ddlColorPicker.SelectedValue);
            addSeries.LegendText = legend;
            addSeries.ToolTip = legend;
            lbSeriesCurrent.Items.Add(liAdded);

            if (!m_seriesCollection.IsSet())
                m_seriesCollection.Value = new List<Series>();

            m_seriesCollection.Value.Add(addSeries);
            showGraph();

        }
        /// <summary>
        /// belongs checks to see if the collection matches the dropdownlist selected,
        /// then checks to see if the date range is within the time frame.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="startDTM"></param>
        /// <param name="endDTM"></param>
        /// <returns></returns>
        private bool belongs(BusAdvertising item, DateTime startDTM, DateTime endDTM)
        {
            if (checkRB(item))
                if (checkTimeFrame(item, startDTM, endDTM))
                    return true;
            return false;
        }
        private bool checkRB(BusAdvertising item)
        {
            if (rbBranch.Checked)
            {
                if (item.Branch == ddlSearchText.SelectedItem.Value)
                    return true;
                return false;
            }
            else if (rbFANumber.Checked)
            {
                if (item.FANumber == ddlSearchText.SelectedItem.Value)
                    return true;
                return false;
            }
            else if (rbRegion.Checked)
            {
                if (item.RegionId.ToString() == ddlSearchText.SelectedItem.Value)
                    return true;
                return false;
            }
            return true;
        }
        private bool checkTimeFrame(BusAdvertising item, DateTime startDTM, DateTime endDTM)
        {
            if ((startDTM.AddDays(-1) < item.DateCreated)
                && (endDTM.AddDays(1) >= item.DateCreated))
                return true;
            return false;
        }
        private List<List<double>> GetDateRange(DateTime startDtm, DateTime EndDtm, List<DateTime> periods)
        {
            List<List<double>> range = new List<List<double>>();
            switch (ddlBreakdown.SelectedValue.ToInt(0))
            {
                case 0:////////////All//////////////////
                    periods.Add(startDtm);
                    range.Add(new List<double>());
                    break;
                case 1://////////Monthly////////////////
                    periods.Add(startDtm);
                    range.Add(new List<double>());
                    //Go to end of month
                    if (startDtm.Day == 1)
                        startDtm = startDtm.AddMonths(1);
                    while (startDtm.Day != 1)
                        startDtm = startDtm.AddDays(1);
                    while (startDtm < EndDtm)
                    {
                        periods.Add(startDtm);
                        range.Add(new List<double>());
                        startDtm = startDtm.AddMonths(1);
                    }
                    break;
                case 3://////////Quarterly//////////////
                    periods.Add(startDtm);
                    range.Add(new List<double>());
                    //Go to end of Quarter
                    if (startDtm.Day == 1 && ((startDtm.Month == 10) || (startDtm.Month == 1) || (startDtm.Month == 4) || (startDtm.Month == 7)))
                        startDtm = startDtm.AddMonths(3);
                    while (startDtm.Day != 1)
                        startDtm = startDtm.AddDays(1);
                    while (!((startDtm.Month == 10) || (startDtm.Month == 1) || (startDtm.Month == 4) || (startDtm.Month == 7)))
                        startDtm = startDtm.AddMonths(1);
                    while (startDtm < EndDtm)
                    {
                        periods.Add(startDtm);
                        range.Add(new List<double>());
                        startDtm = startDtm.AddMonths(3);
                    }
                    break;
                case 12://///Yearly (fiscal)////////////
                    periods.Add(startDtm);
                    range.Add(new List<double>());
                    if (startDtm.Day == 1 && startDtm.Month == 10)
                        startDtm = startDtm.AddYears(1);
                    while (startDtm.Day != 1)
                        startDtm = startDtm.AddDays(1);
                    while (!(startDtm.Month == 10))
                        startDtm = startDtm.AddMonths(1);
                    while (startDtm < EndDtm)
                    {
                        periods.Add(startDtm);
                        range.Add(new List<double>());
                        startDtm = startDtm.AddYears(1);
                    }
                    break;
                case 36:////Tri-Yearly (3 fiscal years)//
                    periods.Add(startDtm);
                    range.Add(new List<double>());
                    if (startDtm.Day == 1 && startDtm.Month == 10)
                        startDtm = startDtm.AddYears(3);
                    while (startDtm.Day != 1)
                        startDtm = startDtm.AddDays(1);
                    while (!(startDtm.Month == 10))
                        startDtm = startDtm.AddMonths(1);
                    while (startDtm < EndDtm)
                    {
                        periods.Add(startDtm);
                        range.Add(new List<double>());
                        startDtm = startDtm.AddYears(3);
                    }
                    break;

                default:
                    break;
            }
            return range;
        }
        private SeriesChartType GetChartType()
        {
            if (ddlChartType.SelectedValue == "Column")
                return SeriesChartType.Column;
            if (ddlChartType.SelectedValue == "Line")
                return SeriesChartType.Line;
            if (ddlChartType.SelectedValue == "Spline")
                return SeriesChartType.Spline;
            if (ddlChartType.SelectedValue == "StepLine")
                return SeriesChartType.StepLine;
            if (ddlChartType.SelectedValue == "Area")
                return SeriesChartType.Area;
            if (ddlChartType.SelectedValue == "SplineArea")
                return SeriesChartType.SplineArea;
            if (ddlChartType.SelectedValue == "Point")
                return SeriesChartType.Point;
            return SeriesChartType.Column;
        }
        private string getLegendName()
        {
            string legendName = string.Empty;
            if (cbAvg.Checked)
                legendName += "(Avg)";
            legendName += ddlSearchBy.SelectedItem.Text;
            if (rbBranch.Checked)
                legendName += "-Branch-" + ddlSearchText.SelectedItem.Text;
            else if (rbFANumber.Checked)
                legendName += "-FA-" + ddlSearchText.SelectedItem.Text;
            else if (rbRegion.Checked)
                legendName += "-Region-" + ddlSearchText.SelectedItem.Text;
            legendName += "~" + ddlChartType.SelectedItem.Text;
            return legendName;
        }
        private void clearChartSeries(List<Series> seriesCollection)
        {
            foreach (Series series in seriesCollection)
                if (chrAdvertising.Series.FindByName(series.Name) != null)
                    chrAdvertising.Series.Remove(chrAdvertising.Series.FindByName(series.Name));

        }
        /// <summary>
        /// Occurs any time a radio button changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rbCheckChanged(object sender, EventArgs e)
        {
            ddlSearchText.Items.Clear();
            if (!rbAll.Checked)
            {
                ddlSearchText.Visible = true;
                populate();
                List<string> possibilities = new List<string>();
                BusAdvertisingCollection ddlCollection = m_AdvertisingCollection.Value;
                foreach (BusAdvertising item in ddlCollection)
                {
                    if (rbBranch.Checked)
                    {
                        if (!possibilities.Contains(item.Branch))
                            possibilities.Add(item.Branch);
                    }
                    else if (rbFANumber.Checked)
                    {
                        if (!possibilities.Contains(item.FANumber))
                            possibilities.Add(item.FANumber);
                    }
                    else if (rbRegion.Checked)
                    {
                        if (!possibilities.Contains(item.RegionId.ToString()))
                            possibilities.Add(item.RegionId.ToString());
                    }
                }
                populateRegions();
                possibilities.Sort();
                foreach (string item in possibilities)
                {
                    ListItem newItem = new ListItem();
                    newItem.Value = item;

                    if (rbRegion.Checked)
                    {
                        foreach (BusRegion region in m_RegionCollection.Value)
                        {
                            if (region.RjRegionId.ToString() == item)
                            {
                                newItem.Text = region.DescText;
                                break;
                            }
                        }
                        if (newItem.Text == "")
                            newItem.Text = item;
                    }
                    else
                        newItem.Text = item;
                    ddlSearchText.Items.Add(newItem);
                }
            }
            else
                ddlSearchText.Visible = false;

        }
        /// <summary>
        /// showGraph happens when the user wants to display the items
        /// in the listbox onto the chart.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void showGraph()
        {
            foreach (ListItem item in lbSeriesCurrent.Items)
                foreach (Series SeriesItem in m_seriesCollection.Value)
                    if ((SeriesItem.Name == item.Text) && (chrAdvertising.Series.FindByName(SeriesItem.Name) == null))
                    {
                        //SeriesItem.Name = //----------------I tried to add by different name each time.
                        chrAdvertising.Series.Add(SeriesItem);
                    }
        }        /// <summary>
        /// Removes all the graph information currently being pulled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRemoveAll_Click(object sender, EventArgs e)
        {
            chrAdvertising.Series.Clear();
            m_seriesCollection.Clear();
            m_RegionCollection.Clear();
            m_AdvertisingCollection.Clear();
            lbSeriesCurrent.Items.Clear();
            lbSeriesNotShown.Items.Clear();
        }

        protected void btnSaveImage_Click(object sender, EventArgs e)
        {
            //chrAdvertising.SaveImage();
        }

    }

Here is the code that didnt past correctly to your reply
 
Share this answer
 
Comments
Anuja Pawar Indore 8-Sep-11 10:35am    
Is your resolved?
MJ_ 9-Sep-11 9:49am    
No it's not, but I have half-solved it by enabling and disabling the series instead of deleteing and readding. The only problem is you can't change the series order this way. Sorry there was just no way to paste the important parts of my code so I never did.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900