Incorrect Axis Labels

Thread is closed for posting
8 posts, 1 answers
  1. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 02 Jul 2013 Link to this post

    This is probably fairly simple, but I have a chart, attached, where the data fed into the chart for the number of feet (along the left) are not what's showing up on the chart itself.  In the case shown, number of feet are actually (4,8,12,16,20,24,28,32,35), but they show up as (4,7,10,13,16,19,22,25,28,31,34) in the bar chart.  Does anyone have any idea what might be happening here?  

  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 03 Jul 2013 Link to this post

    Hi Laurie,

    Most probably the problem is that you are binding the the number of feet as XValues and the chart is calculating its own XAxis Step. You can use PlotArea.XAxis.DataLabelsColumn binding instead, as it will treat the number of feet values as string and will not modify them.

    If this is not the case, it would most helpful if you could provide a runable project or only the code that generates the chart, so we can reproduce the problem on our side and track-down the problem.
     
    Regards,
    Petar Kirov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 09 Jul 2013 Link to this post

    Here is the code I'm using to generate my graph:

    // a. Desired Airflow line
    Telerik.Charting.ChartSeries mySeries1 = rcAirflow.Series[1];
    mySeries1.Items.Clear();
    myItem = new Telerik.Charting.ChartSeriesItem();
    myItem.XValue = 0;
    myItem.YValue = dDesiredAirflow;
    myItem.Label.Visible = false;
    mySeries1.Items.Add(myItem);
    myItem = new Telerik.Charting.ChartSeriesItem();
    myItem.XValue = dNumFeet + 1;
    myItem.YValue = dDesiredAirflow;
    myItem.Label.Visible = false;
    mySeries1.Items.Add(myItem);
     
    // b. Bar Chart
    Telerik.Charting.ChartSeries mySeries0 = rcAirflow.Series[0];
    mySeries0.Items.Clear();
    double dPercentFromDesired = 0.0;
    foreach (FanRequirements myFanRequirements in alFanRequirements)
    {
        myItem = new Telerik.Charting.ChartSeriesItem();
        myItem.YValue = myFanRequirements.CalculatedAirflowPerBu;
        myItem.XValue = myFanRequirements.depth;
        if (myFanRequirements.Equals(alFanRequirements[alFanRequirements.Count - 1]))
        {
            dPercentFromDesired = (myFanRequirements.CalculatedAirflowPerBu - dDesiredAirflow) / dDesiredAirflow;
            if (dPercentFromDesired < -0.05 || dPercentFromDesired > 0.05)
                myItem.Label.TextBlock.Text = myFanRequirements.CalculatedAirflowPerBu.ToString("0.##") + "*";
            else
                myItem.Label.TextBlock.Text = myFanRequirements.CalculatedAirflowPerBu.ToString("0.##");
     
        }
        else
            myItem.Label.TextBlock.Text = myFanRequirements.CalculatedAirflowPerBu.ToString("0.##");
     
        mySeries0.Items.Add(myItem);
    }


    There's some additional code for formatting, but the above is the heart of it.  Since I'm not databinding, I'm not sure how to tell it to see the data as text rather than numeric.
  5. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 11 Jul 2013 Link to this post

    Since I wasn't getting a response here, I opened a ticket on this issue.  I'll post back when I get a fix.
  6. Answer
    Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 12 Jul 2013 Link to this post

    Hi Laurie,

    There are two "modes" of visualizing data - categorical and numerical. In numerical the X axis displays a continuous range (eg. 0 - 1500). When the RadChart.PlotArea.XAxis.AutoScale property is set to true the chart calculates MinValue and MaxValue depending on your data and will try to display ticks and labels at regular intervals (eg. 1, 5, 10, 20, 50, 100, ...) - the Step property. Data points will be rendered on their exact position on the X axis which may or may not coincide with the axis ticks/labels. 

    In categorical mode the XAxis will position the items on equal distance from one another (as if the x axis is not continuous, but behaving like slot collection - each item sits on its own slot) and will display an axis label per each item. This mode is most commonly used with Bar Series where each bar represents a discrete object on the XAxis and a value on the YAxis (categorical X axis and quantitative(numerical) Y axis).

    If you were using data binding, for a categorical chart you would use the ChartSeries.DataXColumn and ChartSeries.DataYColumn properties and for a numerical - ChartSeries.DataYColumn and RadChart.PlotArea.XAxis.DataLabelsColumn. 

    I think that for your scenario a categorical chart will work better. For this you will need to set the RadChart.PlotArea.XAxis.AutoScale property to false, clear the XAxis.Items collection and finally you will need to manually add XAxis items (labels) in the same order as your series items are added to their ChartSeries:

    rcAirflow.PlotArea.XAxis.AutoScale = false;
    rcAirflow.PlotArea.XAxis.Items.Clear();
      
    // a. Desired Airflow line
    Telerik.Charting.ChartSeries mySeries1 = rcAirflow.Series[1];
    mySeries1.Items.Clear();
    myItem = new Telerik.Charting.ChartSeriesItem();
    myItem.XValue = 0;
    myItem.YValue = dDesiredAirflow;
    myItem.Label.Visible = false;
    mySeries1.Items.Add(myItem);
    myItem = new Telerik.Charting.ChartSeriesItem();
    myItem.XValue = dNumFeet + 1;
    myItem.YValue = dDesiredAirflow;
    myItem.Label.Visible = false;
    mySeries1.Items.Add(myItem);
      
    // b. Bar Chart
    Telerik.Charting.ChartSeries mySeries0 = rcAirflow.Series[0];
    mySeries0.Items.Clear();
    double dPercentFromDesired = 0.0;
    foreach (FanRequirements myFanRequirements in alFanRequirements)
    {
        myItem = new Telerik.Charting.ChartSeriesItem();
        myItem.YValue = myFanRequirements.CalculatedAirflowPerBu;
        rcAirflow.PlotArea.XAxis.AddItem(myFanRequirements.depth.ToString());
        if (myFanRequirements.Equals(alFanRequirements[alFanRequirements.Count - 1]))
        {
            dPercentFromDesired = (myFanRequirements.CalculatedAirflowPerBu - dDesiredAirflow) / dDesiredAirflow;
            if (dPercentFromDesired < -0.05 || dPercentFromDesired > 0.05)
                myItem.Label.TextBlock.Text = myFanRequirements.CalculatedAirflowPerBu.ToString("0.##") + "*";
            else
                myItem.Label.TextBlock.Text = myFanRequirements.CalculatedAirflowPerBu.ToString("0.##");
      
        }
        else
            myItem.Label.TextBlock.Text = myFanRequirements.CalculatedAirflowPerBu.ToString("0.##");
      
        mySeries0.Items.Add(myItem);
    }


    Regards,
    Petar Kirov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  7. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 18 Jul 2013 Link to this post

    Thanks, Petar.  That worked almost perfectly.  The "almost" is because the dashed line, that had started at the bottom of the graph and gone to the top of the graph now starts about halfway into the lowest bar.  Any fix for this?

    Thanks.

    Laurie
  8. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 23 Jul 2013 Link to this post

    Hi Laurie,

    Setting the XValue of the first item of the LineSeries to -1 (instead of 0) will make the dashed line to start from the border of the PlotArea.

    I hope this helps.
     
    Regards,
    Petar Kirov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  9. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 23 Jul 2013 Link to this post

    Thanks.  Works perfectly!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017