Gridlines not working?

2 posts, 0 answers
  1. Michael
    Michael avatar
    18 posts
    Member since:
    Jul 2012

    Posted 10 Oct 2012 Link to this post

    I have the following chart set up where I would like to display gridlines:

    <telerik:RadCartesianChart Grid.Row="1">
        <telerik:RadCartesianChart.Behaviors>
            <telerik:ChartTrackBallBehavior />
            <telerik:ChartPanAndZoomBehavior ZoomMode="Horizontal" />
        </telerik:RadCartesianChart.Behaviors>
        <telerik:LineSeries ItemsSource="{Binding PraGasProductionChartPoints}"
                            CategoryBinding="Date"
                            ValueBinding="Value">
            <telerik:LineSeries.HorizontalAxis>
                <telerik:DateTimeContinuousAxis  Minimum="{Binding MinimumChartDate}"
                                                    Maximum="{Binding MaximumChartDate}"
                                                    LabelStyle="{StaticResource labelFontStyle}"
                                                    MajorStepUnit="Year"
                                                    MajorStep="3"
                                                    LabelFormat="yyyy"
                                                    />
            </telerik:LineSeries.HorizontalAxis>
            <telerik:LineSeries.VerticalAxis>
                <telerik:LinearAxis LabelFormat="#,#" />
            </telerik:LineSeries.VerticalAxis>
        </telerik:LineSeries>
        <telerik:RadCartesianChart.Grid>
            <telerik:CartesianChartGrid MajorLinesVisibility="XY" />
        </telerik:RadCartesianChart.Grid>
    </telerik:RadCartesianChart>

    My chart displays fine but I don't get any gridlines to show up on the chart. I assume I'm doing some basic thing wrong. Please help.

    Thanks,
    Mike 
  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 15 Oct 2012 Link to this post

    Hello Michael,

    The problem is that you haven't set the axes of the RadCartesianChart. Instead only the LineSeries have a reference to the axes you have defined. The ChartView Grid needs a reference to the chart's axes, in order to be rendered.

    Moving the definitions of the axes from the LineSeries.Vertical/HorizontalAxis to RadCartesianChart.Vertical/HorizontalAxis should solve your problem.

    The Vertical/HorizontalAxis properties of the CartesianSeries are only used when you want to have additional axes. This help topic explains how to use them.

    Here is a modified version of your code: 
    <telerik:RadCartesianChart>          
        <telerik:RadCartesianChart.Behaviors>
            <telerik:ChartTrackBallBehavior />
            <telerik:ChartPanAndZoomBehavior ZoomMode="Horizontal" />
        </telerik:RadCartesianChart.Behaviors>
                  
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:DateTimeContinuousAxis  Minimum="{Binding MinimumChartDate}"
                                  Maximum="{Binding MaximumChartDate}"
                                  MajorStepUnit="Year"
                                  MajorStep="3"
                                  LabelFormat="yyyy" />
        </telerik:RadCartesianChart.HorizontalAxis>
                  
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis LabelFormat="#,#" />
        </telerik:RadCartesianChart.VerticalAxis>
                  
            <telerik:LineSeries
                         ItemsSource="{Binding PraGasProductionChartPoints}"
                         CategoryBinding="Date"
                         ValueBinding="Value"/>
                  
        <telerik:RadCartesianChart.Grid>
            <telerik:CartesianChartGrid MajorLinesVisibility="XY" />
        </telerik:RadCartesianChart.Grid>
    </telerik:RadCartesianChart>


    All the best,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top