Change type of axis dynamicaly (from code) via a combobox

1 Answer 62 Views
Chart ComboBox
Didier
Top achievements
Rank 2
Iron
Iron
Didier asked on 15 Sep 2021, 03:11 PM

Hi all,

 

I have a chart : RadCarteisaonChart defined like this :
Is possible to change the Axis (X and Y) by Logarithmics Axis at runtime ?

Regards


 <telerik:RadCartesianChart Grid.Column="0" Margin="0,30,0,30" Foreground="{StaticResource DarkGray}">
                            <telerik:RadCartesianChart.HorizontalAxis>
                                <telerik:LinearAxis x:Name="hLinearAxis" ShowLabels="True">
                                </telerik:LinearAxis>
                                <!--<telerik:LogarithmicAxis x:Name="hLogarithmAxis" ShowLabels="True">
                                </telerik:LogarithmicAxis>-->                                
                            </telerik:RadCartesianChart.HorizontalAxis>
                            <telerik:RadCartesianChart.VerticalAxis>
                                <telerik:LinearAxis x:Name="vAxis"/>
                            </telerik:RadCartesianChart.VerticalAxis>
                            <telerik:ScatterPointSeries x:Name="ChartCurve" XValueBinding="Concentration" YValueBinding="OpticalDensity" Foreground="{StaticResource DarkGray}">
                                <telerik:ScatterPointSeries.PointTemplate>
                                    <DataTemplate>
                                        <Ellipse Width="10" 
                                                Height="10" 
                                            Fill="{StaticResource ElectricBlue}"/>
                                    </DataTemplate>
                                </telerik:ScatterPointSeries.PointTemplate>
                            </telerik:ScatterPointSeries>
                            <telerik:RadCartesianChart.Grid>
                                <telerik:CartesianChartGrid MajorLinesVisibility="XY" />
                            </telerik:RadCartesianChart.Grid>
                            <telerik:RadCartesianChart.Annotations>
                                <telerik:CartesianCustomLineAnnotation Stroke="Red" StrokeThickness="2" HorizontalFrom="0" HorizontalTo="{Binding CONCMAX}" VerticalFrom="{Binding A}" VerticalTo="{Binding YMAX}" />
                            </telerik:RadCartesianChart.Annotations>
                        </telerik:RadCartesianChart>

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 17 Sep 2021, 08:27 AM

Hello Didier,

You can achieve this by setting the VerticalAxis and HorizontalAxis properties of the chart in code behind. The following example code snippet changes the axes on a button click:

private void RadButton_Click(object sender, RoutedEventArgs e)
{
    if (this.chart.VerticalAxis is LinearAxis && this.chart.HorizontalAxis is LinearAxis)
    {
        this.chart.VerticalAxis = new LogarithmicAxis() { LogarithmBase = 2 };
        this.chart.HorizontalAxis = new LogarithmicAxis() { LogarithmBase = 2, ShowLabels = true };
    }
    else
    {
        this.chart.VerticalAxis = new LinearAxis();
        this.chart.HorizontalAxis = new LinearAxis() { ShowLabels = true };
    }
}

That said, I have prepared a sample project implementing the following approach.

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Chart ComboBox
Asked by
Didier
Top achievements
Rank 2
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or