How to align multiple Y axis ticks in one Graph
Hello,
I have a two questions:
- I'm trying to align multiple y axis but I can't (see attachment). I tried downloading a solution (provided 11 years ago) and is not available. Can you help?
- Is there a way to RESET the Axis MIN and MAX once its set?
Example: I'm trying to add an option for Auto Scale or Manual Scale (see attachment); once I set a min and max I can't go back to the original scaling.
Thanks!
Attachment: question_4a455243.zip
SIGN IN To post a reply.
4 Replies
GM
Gayathri Manickam
Syncfusion Team
October 4, 2021 12:57 PM UTC
Hi Jose,
Greetings from Syncfusion.
Query 1 : Align multiple Y-axis in the same gridline.
Solution 1: In Multiple axes, by setting same value for Minimum and Maximum property for the multiple axis, you can align the axis gridlines in the single grid.
XAML:
|
<syncfusion:SfChart.SecondaryAxis>
<syncfusion:NumericalAxis Minimum="0" Maximum="200" x:Name="yaxis" />
</syncfusion:SfChart.SecondaryAxis> |
Solution 2 : We have achieved your requirement by extending NumericalAxis and overriding GenerateVisibleLabels method to add the axis labels with equal interval. By default, axis labels are calculated based on the nice interval generated from the provided data points. Please refer the below code snippet,
Code snippet[C#] :
|
public class NumericalAxisExt : NumericalAxis
{
protected override void GenerateVisibleLabels()
{
base.GenerateVisibleLabels();
List<double> TickPosition = new List<double>();
double position;
if (VisibleLabels != null)
{
VisibleLabels.Clear();
//Considered that we need 10 labels. so divided by 10.
var interval = (VisibleRange.End - VisibleRange.Start) / 10;
PropertyInfo property = typeof(ChartAxis).GetProperty("TickPositions", BindingFlags.Instance | BindingFlags.NonPublic);
var start = VisibleRange.Start;
position = VisibleRange.Start - (VisibleRange.Start % interval);
while (start <= VisibleRange.End)
{
VisibleLabels.Add(new ChartAxisLabel(start, start.ToString()));//Set label format if needed.
start += interval;
TickPosition.Add(position);
position += interval;
}
property?.SetValue(this, TickPosition);
}
}
} |
XAML:
|
<syncfusion:SfChart x:Name="chart">
…
<syncfusion:SfChart.SecondaryAxis>
<local:NumericalAxisExt x:Name="yaxis"
</syncfusion:SfChart.SecondaryAxis>
<syncfusion:SfChart.Series>
<syncfusion:FastLineSeries ItemsSource="{Binding LineData1}" XBindingPath="XValue" YBindingPath="YValue"/>
<syncfusion:FastLineSeries ItemsSource="{Binding LineData2}"
XBindingPath="XValue" YBindingPath="YValue">
<syncfusion:FastLineSeries.YAxis>
<local:NumericalAxisExt x:Name="yaxis1" OpposedPosition="True"/>
</syncfusion:FastLineSeries.YAxis>
</syncfusion:FastLineSeries>
</syncfusion:SfChart.Series>
</syncfusion:SfChart> |
Query 2: How to reset axis Minimum and Maximum once its set?
By setting NaN value to the Minimum and Maximum property, you can reset the Minimum and Maximum of the axis
Code snippet[C#] :
|
yaxis.Minimum = double.NaN;
yaxis.Maximum = double.NaN; |
Thanks
Gayathri M.
JM
JOSE M. MENDEZ
October 4, 2021 04:45 PM UTC
Hello,
Thanks for your reply. I still have some issues:
Once I set Min/Max to NaN to reset the axis; it no longer automatically autoscale the axis.
Example: if I do not specify Min/Max in the graph then it updates the axis correctly (automatically); but once I set Min/Max to NaN and re-plot a curve, it no longer updates the axis.
GM
Gayathri Manickam
Syncfusion Team
October 5, 2021 12:48 PM UTC
Hi Jose,
Our support team has taken out your query, and we will update you the complete details by tomorrow October 6, 2021.
Thanks
Gayathri M.
DD
Devakumar Dhanapoosanam
Syncfusion Team
October 6, 2021 05:06 PM UTC
Hi Jose,
Thanks for your patience.
The numeric axis default range is 0 to 1 if you are not given series ItemsSource data, else based on series data nice interval range will be calculated automatically for axis. If you are setting manual value for Minimum/Maximum properties in axis it will be applied.
Query: Once I set Min/Max to NaN to reset the axis; it no longer automatically autoscale the axis.
We can resolve it by setting as null value instead of double.NaN for the Minimum/Maximum properties as per in the below code example.
Query: Once I set Min/Max to NaN to reset the axis; it no longer automatically autoscale the axis.
We can resolve it by setting as null value instead of double.NaN for the Minimum/Maximum properties as per in the below code example.
|
private void Button_Click1(object sender, RoutedEventArgs e)
{
yaxis.Minimum = null;
yaxis.Maximum = null;
} |
Please find the sample from below link
Please check the above solution and let us know whether resolves your requirement or not. If not, can you please share more details for your requirement or by modifying the above sample based on your application scenario which will be helpful for us to providing you better solution at the earliest?
Devakumar D
SIGN IN To post a reply.
- 4 Replies
- 3 Participants
-
JM JOSE M. MENDEZ
- Oct 1, 2021 11:11 PM UTC
- Oct 6, 2021 05:06 PM UTC