Logarithm Base at Runtime / MVVM

7 posts, 0 answers
  1. Courouble Damien
    Courouble Damien avatar
    54 posts
    Member since:
    Aug 2009

    Posted 16 Aug 2011 Link to this post

    Hi Guys,

    i'm binding the LogarithmBase and the isLogarithm on the Axis Y
    Everything looks okay, but i need to change this option at runtime by the help of a checkbox for enable / disable the log and a combobox for changing the base.
    At runtime changing the base or the isLog option doesn't refresh update the chart as it suppose to be.

    i found that changing the value of the isInverse refresh correctly the chart, so as a workaround i just set IsInverse twice to the inverse of himself ( so the value remain the same but looks change)

    I'm okay with this workaround but that would be aweseome if it could works without that !!

    here's my code, that may help you

    Thanks,

    Damien

    ''' <summary>
           ''' Get or set a boolean indicating if the YAxis is log or not
           ''' </summary>
           ''' <value></value>
           ''' <returns></returns>
           ''' <remarks></remarks>
           Public Property YAxisIsLogarithmic() As Boolean
               Get
                   Return _YAxisIsLogarithmic
               End Get
               Set(ByVal value As Boolean)
                   If Not Boolean.Equals(_YAxisIsLogarithmic, value) Then
                       _YAxisIsLogarithmic = value
                       Properties.SetElementValue("YAxisIsLogarithmic", value.ToString())
                       RaisePropertyChanged("YAxisIsLogarithmic")
                       ' Work around for log bug we need to change the value of the inverse and then put the value back
                       YAxisIsInverse = Not YAxisIsInverse
                       YAxisIsInverse = Not YAxisIsInverse
                   End If
               End Set
           End Property
     
           ''' <summary>
           ''' Get or set the log base for YAxis
           ''' </summary>
           ''' <value></value>
           ''' <returns></returns>
           ''' <remarks></remarks>
           Public Property YAxisLogarithmBase() As Integer
               Get
                   Return _YAxisLogarithmBase
               End Get
               Set(ByVal value As Integer)
                   If Not Integer.Equals(_YAxisLogarithmBase, value) Then
                       _YAxisLogarithmBase = value
                       Properties.SetElementValue("YAxisLogarithmBase", value.ToString())
                       RaisePropertyChanged("YAxisLogarithmBase")
                       ' Work around for log bug we need to change the value of the inverse and then put the value back
                       YAxisIsInverse = Not YAxisIsInverse
                       YAxisIsInverse = Not YAxisIsInverse
     
                   End If
               End Set
           End Property
     
    ''' <summary>
           ''' Get or set a boolean value indicating if the Axis is inverse or not
           ''' </summary>
           ''' <value></value>
           ''' <returns></returns>
           ''' <remarks></remarks>
           Public Property YAxisIsInverse() As Boolean
               Get
                   Return _YAxisIsInverse
               End Get
               Set(ByVal value As Boolean)
                   If Not Boolean.Equals(_YAxisIsInverse, value) Then
                       _YAxisIsInverse = value
                       Properties.SetElementValue("YAxisIsInverse", value.ToString())
                       RaisePropertyChanged("YAxisIsInverse")
                   End If
               End Set
           End Property

    And the XAML As Well ..

    <!-- Y Axis -->
                            <telerik:ChartArea.AxisY>
                                <telerik:AxisY Title="{Binding YAxisTitle}"
                                               IsInverse="{Binding YAxisIsInverse}"
                                               AutoRange="{Binding YAxisIsAutoRange}"
                                               IsZeroBased="{Binding YAxisIsZeroBased}"
                                               IsLogarithmic="{Binding YAxisIsLogarithmic}"
                                               LogarithmBase="{Binding YAxisLogarithmBase}"
                                               MinValue="{Binding YAxisMinValue}"
                                               MaxValue="{Binding YAxisMaxValue}"
                                               Step="{Binding YAxisStep}"
                                               AxisLabelsVisibility="{Binding YAxisLabelsVisible, Converter={StaticResource BooleanToVisibilityConverter}}"   
                                               LabelRotationAngle="{Binding YAxisLabelsRotation}"
                                               MinorGridLinesVisibility="{Binding YAxisMinorGridLinesVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                                               MajorGridLinesVisibility="{Binding YAxisMajorGridLinesVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                                               StripLinesVisibility="{Binding YAxisStripLinesVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                                               DefaultLabelFormat="{Binding YAxisLabelsFormat}"/>
                          </telerik:ChartArea.AxisY>
  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 18 Aug 2011 Link to this post

    Hello,

    Thanks for the details. The problem appears only when Authoring is set to false, so you may want to limit the workaround to be applied only in this case.

    You can find the issue logged here. I have updated your Telerik points for bringing this to our attention.

    Best regards,
    Ves
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. Courouble Damien
    Courouble Damien avatar
    54 posts
    Member since:
    Aug 2009

    Posted 19 Aug 2011 Link to this post

    Thanks for tracking this issue.
    But I'm sorry what's Authoring ?? Is it AutoRange / Auto Scale ? 

    Thanks

    Damien
  4. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 23 Aug 2011 Link to this post

    Hi,

    I am sorry about that -- I must have clicked the wrong option in the spellchecker. Indeed, it should read:

    ...when AutoRange is set to false...



    Best regards,
    Ves
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  5. AndreasW
    AndreasW avatar
    13 posts
    Member since:
    Jul 2011

    Posted 04 Oct 2011 Link to this post

    Hi,
    I am struggling with the same issue, but in my case setting AutoRange to True does not fix the issue. Any fix for this yet?


    In my case the  Chart.AxisY are bound to a bool in the ViewModel controlled by a Checkbox.
    When the axis are changed for the first time from logarithmic to linear it works as expected, but when when trying to change back to logarithmic the AxisY values remains unchanged and every graph line are drawn with Yvalue = 0.

    I have treid both Rebind() and the workaround with IsInversed() without luck.

    XAML for my chart


    <telerik:RadChart x:Name="Chart" Height="550" ItemsSource="{Binding CM}" UseDefaultLayout="True">                 
       <telerik:RadChart.SeriesMappings>
           <telerik:SeriesMapping LegendLabel="Item" ChartAreaName="AreaNavn" >
              <telerik:SeriesMapping.SeriesDefinition>
                   <telerik:LineSeriesDefinition Visibility="{Binding IsVisible, Source={StaticResource VM}}"  ShowItemLabels="True"/>
                </telerik:SeriesMapping.SeriesDefinition>
                        <telerik:ItemMapping FieldName="Item" DataPointMember="YValue"/>
                        <telerik:ItemMapping FieldName="Year" DataPointMember="XValue"/>
                 </telerik:SeriesMapping>
                   <telerik:RadChart.DefaultView>
                        <telerik:ChartDefaultView ChartLegendPosition="Right"
                              <telerik:ChartDefaultView.ChartArea>
                               <telerik:ChartArea LegendName="chartLegend">
                                   <telerik:ChartArea.AxisX>
                                     <telerik:AxisX
                                    
                                    MajorTicksVisibility="Collapsed"
                                    AutoRange="False"
                                    MinorGridLinesVisibility="Visible"
                                    MaxValue="{Binding SelectionEnd, ElementName=DateSlider}"
                                    MinValue="{Binding SelectionStart, ElementName=DateSlider}"
                                    IsDateTime="False"
                                    DefaultLabelFormat="#VAL{}"
                                    LabelRotationAngle="45"
                                                                     
                                                               />
                                   </telerik:ChartArea.AxisX>
                                    <telerik:ChartArea.AxisY>
                                            <telerik:AxisY
                                              x:Name="AxisY"
                                              IsLogarithmic="{Binding IsLog, Source={StaticResource MalingerVM}}"
                                              LogarithmBase="10"
                                              MajorTicksVisibility="Collapsed"
                                              AutoRange="True" 
                                              ExtendDirection="None"
                                                                            />
                                                </telerik:ChartArea.AxisY>
                                                                </telerik:ChartArea>
                                        </telerik:ChartDefaultView.ChartArea>
                                        <telerik:ChartDefaultView.ChartLegend>
                                             <telerik:ChartLegend
                                                 UseAutoGeneratedItems="True"
                                                  Header="Items"
                                                  x:Name="chartLegend"
                                                  Width="150"
                                                  LegendItemStyle="{StaticResource CustomLegendItemStyle}" LegendItemMarkerShape="Square"/>
                                        </telerik:ChartDefaultView.ChartLegend>
                                    </telerik:ChartDefaultView>
                                </telerik:RadChart.DefaultView>                           
                                </telerik:RadChart>
            



    Any idea how I can fix this issue?
  6. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 07 Oct 2011 Link to this post

    Hi Andreas,

    Please, find attached a small example, based on your markup and with AutoRange=true,  which works correctly for me.

    Best regards,
    Ves
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  7. AndreasW
    AndreasW avatar
    13 posts
    Member since:
    Jul 2011

    Posted 10 Oct 2011 Link to this post

    I found the problem. My datas contained zero values, wich do not go to well with log scale.




    Greeting
    Andreas
Back to Top