This is a migrated thread and some comments may be shown as answers.

Incorrect Axis Labels

7 Answers 25 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Laurie
Top achievements
Rank 2
Laurie asked on 02 Jul 2013, 04:31 PM
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?  

7 Answers, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 03 Jul 2013, 07:43 AM
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.
0
Laurie
Top achievements
Rank 2
answered on 09 Jul 2013, 08:43 PM
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.
0
Laurie
Top achievements
Rank 2
answered on 11 Jul 2013, 03:00 PM
Since I wasn't getting a response here, I opened a ticket on this issue.  I'll post back when I get a fix.
0
Accepted
Petar Kirov
Telerik team
answered on 12 Jul 2013, 05:56 PM
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.
0
Laurie
Top achievements
Rank 2
answered on 18 Jul 2013, 09:52 PM
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
0
Petar Kirov
Telerik team
answered on 23 Jul 2013, 10:36 AM
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.
0
Laurie
Top achievements
Rank 2
answered on 23 Jul 2013, 04:21 PM
Thanks.  Works perfectly!
Tags
Chart (Obsolete)
Asked by
Laurie
Top achievements
Rank 2
Answers by
Petar Kirov
Telerik team
Laurie
Top achievements
Rank 2
Share this question
or