7 Answers, 1 is accepted
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
// 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.
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);
}
Petar Kirov
Telerik
Thanks.
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