RadChart Legend Will Not Show New Items

2 posts, 0 answers
  1. Marie C
    Marie C avatar
    5 posts
    Member since:
    Mar 2010

    Posted 28 Jan 2013 Link to this post

    I have a RadChart (2011.2.920.1040) that is filled in code behind using WCF results. The user is allowed to pick the data they want to chart.  This works the first time but if they make a second choice, the legend is empty. 

    Before I cleared the dataseries, the chart and legend kept the old data along with the new.  Now that I have cleared the dataseries, if the user makes a second selection, the legend is empty. 

    I manually added a legend item to the ChartLegend and the associated legend but the legend is still empty. 

    // Global Variables

     

     

    RadChart chartName =

    new RadChart();

     

     

     

    ChartLegend chartLegend =

     

     

    new ChartLegend();

     

     

     

    // SET LEGEND TO CHARTAREA

     

    chartName.DefaultView.ChartArea.LegendName =

     

    "chartLegend";

     

     

     


    // Clear the previously plotted data if this is not the first time through
    chartName.DefaultView.ChartArea.Legend.Items.Clear();
    chartName.DefaultView.ChartArea.DataSeries.Clear();


     

    // CREATE A SERIES FOR EACH SENSOR RETURNED.

     

     

    foreach (var sensorItem in sensorReturned)

     

    {

     

     

    DataSeries lineSeries = new DataSeries();

     

    lineSeries.LegendLabel = sensorItem.ToString();

    lineSeries.Definition =

     

    new LineSeriesDefinition();

     

     

     

    var sensorPlotItems = (from p in e.Result 
                            where p.SensorName == sensorItem
                            
    select p).ToList();

     

     

     

    foreach (var item in sensorPlotItems)

     

    {

    lineSeries.Add(

     

    new DataPoint() { XCategory = item.TimeStamp.ToString(), YValue = item.SelectedFieldValue, LegendLabel = sensorItem.ToString() });

     

    }

    chartName.DefaultView.ChartArea.DataSeries.Add(lineSeries);

     

     

    ChartLegendItem legendItem = new ChartLegendItem();

     

    legendItem.Label = sensorItem.ToString();

    chartLegend.Items.Add(legendItem);

    chartName.DefaultView.ChartLegend.Items.Add(legendItem);

     

     

    // TEST TO SEE IF THE NEWLY ADDED LEGEND ITEM IS INSIDE THE LEGEND

     

     

     

    bool associatedLegendFilled = chartLegend.HasItems; // true but nothing shows

     

     

     

    bool filled = chartName.DefaultView.ChartLegend.HasItems; // false

     

    }

    Any ideas?

  2. Marie C
    Marie C avatar
    5 posts
    Member since:
    Mar 2010

    Posted 28 Jan 2013 Link to this post

    Problem solved.  I removed the line setting the chartName.DefaultView.ChartLegend.ItemsSource = null.  All works fine now. 

     

     

    // CLEAR ALL DATA FROM SELECTEDSENSORS AND CHART

     

    selectedSensors.Clear();

     

     

    chartName.ItemsSource =

    null;

     

    chartName.DefaultView.ChartArea.ItemsSource =

     

     

     

    null;

     

     

     

    //chartName.DefaultView.ChartLegend.ItemsSource = null;

     

    chartName.DefaultView.ChartArea.AxisX.ChartArea.ItemsSource =

     

    //chartName.DefaultView.ChartLegend.ItemsSource = null;

     

     

     

     

     

     

    null;

     

    chartName.DefaultView.ChartArea.Legend.Items.Clear();

     

     

    chartName.DefaultView.ChartArea.DataSeries.Clear();

  3. DevCraft banner
Back to Top