We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

SfChart and multiple axes

Thread ID:

Created:

Updated:

Platform:

Replies:

127189 Nov 1,2016 03:14 PM Nov 4,2016 11:21 AM WPF 6
loading
Tags: Chart
Matthew Z
Asked On November 1, 2016 03:14 PM

Hi,

I am attempting to migrate from a different 2D chart solution where I had one chart control. My apologies for not posting code. In this case, I had multiple axes that were shown based on data triggers in styles for different sets of data. One set of data was plotted on a semi-logarithmic basis where the X axis data is logarithmic and the Y axis data is linear. Only one Y axis and only one X axis was shown at any one time for its respective data set.

I have attached screenshots of the previous 2D chart solution that show one set of linear data and one set of semi-logarithmic data.

In the previous solution, all Y axis data was was linear so I figure that a singular Y axis would quite possibly work in SfChart for all the different data sets if I set the appropriate properties based on data triggers, e.g., maximum, minimum, etc.

However, I have to show either a linear X axis or a logarithmic X axis independently of each other for the appropriate data set. I note that there seems to be no way to assign two different axes to SfChart.PrimaryAxis, and I read the documentation at https://help.syncfusion.com/wpf/sfchart/axis#multiple-axes regarding multiple axes; unfortunately, for my needs it is not the solution that I need.

I have also tried another solution of having an SfChart control only for linear data where the "Visibility" property of the chart control is set based on data triggers. I assumed that I would be able to use this SfChart instance for the linear data and another SfChart instance for semi-log data. However, in brief testing, I note that if I select my UI controls so that the linear chart is not visible and then I select the UI controls so that the linear chart should be visible, nothing is shown.

The caveat is that if I first show the chart control with the linear data, select the controls so that chart is then hidden, and then set the controls so that chart should be visible, the chart is shown when it should be in this scenario. I have not yet added a second SfChart control to the project for the semi-log data; however, I figure what I did should have provided proof of concept.

What is the recommended way of handling a usage scenario like this?

Thank you.

Attachment: Charts_6221bdd0.zip

Devi Aruna Maharasi Murugan [Syncfusion]
Replied On November 2, 2016 08:14 AM

Hi Matthew, 
  
Thanks for contacting Syncfusion Support. 
  
We are able to achieve your requirement (linear X axis for one data set and Logarithmic axis for another data set) by defining the X-Axis for chart series. Also, by enabling and disabling the corresponding x-axis and series visibility while data triggering, we can switch between linear x-axis and logarithmic x-axis. 
  
We have prepared a demo sample based on your requirement and it can be downloaded from below link, 
  
Sample:  MultipleAxis 
  
Regards, 
Devi 




Matthew Z
Replied On November 2, 2016 03:35 PM

The sample works fine.

However, in my case, the two different scenarios in which I have semi-log data have multiple series in them. In all cases, there is at least one reference curve, and then a curve plotted with data that is based on a particular analysis. If I do not assign an XAxis to a semi-log series, the series itself fails to display even though its IsSeriesVisible property is set to true. If I set each series in the semi-log case with their own XAxis, then both series display, however, they are plotted against their own XAxis; this makes interpretation of the data difficult. I need all series in a semi-log data set to be plotted against a singular XAxis. I am attaching screenshots of the results for both the linear and the semi-log cases.

Now that I have bound the data for one of the semi-log data sets to line series in SfChart, I am going to try once again to utilize two different SfChart objects, one for each data set to see if that now will work as the problems that I saw with the chart not showing at all no longer appear to manifest.

Attachment: linear1_281e18e.zip

Devi Aruna Maharasi Murugan [Syncfusion]
Replied On November 3, 2016 08:49 AM

Hi Matthew, 
  
Thanks for your update. 
  
We have achieved your requirement (multiple series with single X-Axis) by binding single x-axis to multiple series XAxis property as shown in the below code snippet 
  
      
      <chart:LineSeries Name="line1"> 
        <chart:LineSeries.XAxis> 
          <chart:LogarithmicAxis Name="logAxis"/> 
        </chart:LineSeries.XAxis> 
      </chart:LineSeries> 
 
      <chart:LineSeries Name="line2" XAxis="{Binding XAxis ,ElementName=line1}"/> 
      <chart:LineSeries Name="line3" XAxis="{Binding XAxis ,ElementName=line1}" /> 
 
  
We have prepared a demo sample based on your requirement and it can be downloaded from below link, 
  
Sample: MultipleLogAxis 
  
Regards, 
Devi 





Matthew Z
Replied On November 3, 2016 03:27 PM

Thank you for your help.

I was able to get this to work, however, when using the binding with the ElementName property, I get the following binding error:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=snContactReferenceLine'. BindingExpression:Path=XAxis; DataItem=null; target element is 'FastLineSeries' (Name=''); target property is 'XAxis' (type 'ChartAxisBase2D')

When I get this error, the series that binds to the XAxis fails to display.

On researching this, there is information out there that the visual tree may not be properly preserved. In fact, I seem to be getting these errors only with SfChart, FastLineSeries, NumericalAxis and LogarithmicAxis. I have not gotten them with other packages I have tried.

I did, however, get it to work with the following xaml:

                                XAxis="{Binding Source={x:Reference snContactReferenceLine}, Path=XAxis}"/>

In general, the "Source={x:Reference "name"} syntax seems to solve the issue when I see it; however, I am somewhat concerned about this as the binding with the ElementName property should work.

Thanks again.



Matthew Z
Replied On November 3, 2016 04:07 PM

One more thing.

Perhaps this should be a separate issue, however, I note that with this method, if I set the default visibility of either the PrimaryAxis or the XAxis on the logarithmic series to "Collapsed" I get extraneous grid lines. Please see the attached screenshot.

The associated xaml is

        <Style x:Key="syncfLinearAxis" TargetType="syncfusion:NumericalAxis">
            <Setter Property="Visibility" Value="Collapsed"/>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Source={x:Reference ti2D}, Path=IsSelected}" Value="True"/>
                        <Condition Binding="{Binding ElementName=tiRootBending, Path=IsSelected}" Value="True"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Visibility" Value="Visible"/>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>

The base control for this is a UserControl, and the style is defined in the UserControl.Resources property.

Here is the xaml from the SfChart:

                        <syncfusion:SfChart.PrimaryAxis>
                            <syncfusion:NumericalAxis Style="{StaticResource syncfLinearAxis}"
                                Header="{x:Static props:Resources.plot2DBendingXAxisTitle}"
                                LabelFormat="{x:Static props:Resources.bending2DRootNodeAxisFormatString}"
                                Minimum="1" Maximum="{Binding Path=ElementsAlongFace}"/>
                        </syncfusion:SfChart.PrimaryAxis>

However, if I make the default Visibility "Hidden" with the same style except that the value for the Visibility is "Hidden" as in the following xaml:

        <Style x:Key="syncfLinearAxis" TargetType="syncfusion:NumericalAxis">
            <Setter Property="Visibility" Value="Hidden"/>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Source={x:Reference ti2D}, Path=IsSelected}" Value="True"/>
                        <Condition Binding="{Binding ElementName=tiRootBending, Path=IsSelected}" Value="True"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Visibility" Value="Visible"/>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>

The extraneous grid lines disappear. This happens on both the NumericalAxis and the LogarithmicAxis.

Thanks again.

Best Regards,
Matthew

Attachment: ExtraneousGridLines_a36576d7.zip

Devi Aruna Maharasi Murugan [Syncfusion]
Replied On November 4, 2016 11:21 AM

Hi Matthew, 
  
Thanks for your update. 
  
We have tried to reproduce the reported problem at our end with provided details and we are unable to reproduce the issue at our end. We have a demo sample based on your use case and it can be downloaded from below link, 
  
Sample: AxisVisiblity 
  
If you are still able to reproduce the reported problem, please revert us by modifying the sample. It would be helpful for us to serve you better. 
  
Regards, 
Devi 




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;