Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:35:17+00:00 2026-06-17T09:35:17+00:00

I have an Silverlight 5 application which is using the Silverlight Toolkit. Now, the

  • 0

I have an Silverlight 5 application which is using the Silverlight Toolkit. Now, the Silverlight Toolkit chart control doesnt always show X axis values when there is only one result in the resultset that returns from my webserivce.

X-Axis works!!
With 1 item in the resultset, the X-Axis seems to disappear

The first image shows that my chart is loaded properly when selecting a big enough resultset.
The second image shows that it doesn’t when the resultset exists of 1 item.

This is my implementation:

TimeSpan monthSpan = TimeSpan.FromDays(30.0);
TimeSpan daySpan = TimeSpan.FromDays(1.0);
TimeSpan hourSpan = TimeSpan.FromHours(1.0);

foreach (TagValueResult res in e.NewItems)
{
    if (res != null)
    {
        LineSeries lineSeries = new LineSeries()
        {
            Title = string.Format("{0}" + Environment.NewLine + " {2} ({1})", res.Name, res.Attributes["UOM"], res.Attributes["Description"]),
            ItemsSource = res.Values,
            DependentValueBinding = new System.Windows.Data.Binding("Value"),
            IndependentValueBinding = new System.Windows.Data.Binding("Key"),
            Tag = res,
            PolylineStyle = Resources["thinLineStyle"] as Style,
            //DataPointStyle = Resources["dataPointStyle"] as Style
        };
        if (res.Values.Any() && chart.Series.Any() == false)
        {
            TimeSpan graphSpan = res.Values.ToList().Last().Key - res.Values.ToList().First().Key;

            lineSeries.IndependentAxis = new DateTimeAxis
            {
                Minimum = res.Values.ToList().First().Key,
                Maximum = res.Values.ToList().Last().Key,
                Interval = 1,
                Orientation = AxisOrientation.X,
                Location = AxisLocation.Bottom
            };

            if (graphSpan > monthSpan)
            {
                ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days;
                ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 5;
            }
            else if (graphSpan > daySpan && graphSpan < monthSpan)
            {
                ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days;
                ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1;
            }
            else if (graphSpan > hourSpan && graphSpan < daySpan)
            {
                ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Hours;
                ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1;
            }
            else if (graphSpan < hourSpan)
            {
                ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Minutes;
                ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 15;
            }
            else
            {
                //sometimes all comparisons fail, just back up to a safe interval of 1 day.
                ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days;
                ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1;
            }
        }
        chart.Series.Add(lineSeries);
    }
}

Do you have any idea’s? I’m out of possible solutions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:35:18+00:00Added an answer on June 17, 2026 at 9:35 am

    A collection with one item will have incorrect behavior in several places of your code.

    Here graphSpan will equal zero:

    TimeSpan graphSpan = res.Values.ToList().Last().Key - res.Values.ToList().First().Key;
    

    And here Maximum and Minimum will be the same:

    lineSeries.IndependentAxis = new DateTimeAxis
    {
        Minimum = res.Values.ToList().First().Key,
        Maximum = res.Values.ToList().Last().Key,
    

    I suggest that you add another if-block and construct a different axis for the special case when the collection has only 1 item.

    var values = res.Values.ToList();
    TimeSpan graphSpan = values.Last().Key - values.First().Key;
    
    if (graphSpan == TimeSpan.Zero)
    {
        lineSeries.IndependentAxis = new DateTimeAxis
        {
            Orientation = AxisOrientation.X,
            Location = AxisLocation.Bottom
        };
    }
    else
    {
        lineSeries.IndependentAxis = new DateTimeAxis
        {
            Minimum = values.First().Key,
            Maximum = values.Last().Key,
            Orientation = AxisOrientation.X,
            Location = AxisLocation.Bottom
        };
    
        if (graphSpan > monthSpan)
        {
            ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days;
            ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 5;
        }
        else if (graphSpan > daySpan && graphSpan < monthSpan)
        {
            ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days;
            ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1;
        }
        else if (graphSpan > hourSpan && graphSpan < daySpan)
        {
            ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Hours;
            ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1;
        }
        else if (graphSpan < hourSpan)
        {
            ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Minutes;
            ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 15;
        }
        else
        {
            //sometimes all comparisons fail, just back up to a safe interval of 1 day.
            ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days;
            ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight 4 desktop application which I control using a touchscreen (on
I have an MVC application which uses a silverlight control. Somewhere along the line
I'm using a DataPager control in my silverlight application. I have different pagers for
I have a silverlight based application consisting of charts using silverlight toolkit and connected
I have a silverlight application which reads data from a db and displays them
I have a silverlight application which users will be running in various time zones
I have a Silverlight application in which I catch certain key presses such as
I have a Silverlight 4 application which gets data from a silverlight enabled WCF
I have a Silverlight application in which I am doing the following thing to
I have a client-server Silverlight application, which is use Socets. I have server appliaction

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.