This is a migrated thread and some comments may be shown as answers.

Collapsed Y Axis breaks PlotAreaMouseLeftButtonUp/Down

3 Answers 68 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michele
Top achievements
Rank 1
Michele asked on 12 Jun 2012, 05:54 PM
Hi,

I am using a Telerik Silverlight chart in my application. I need to collapse my Y axis and at the same time I need to interact with the PlotArea using the PlotAreaMouseLeftButtonUp/Down event handler.
The PlotAreaMouseLeftButtonUp/Down events work just fine with a visible Y axis but as soon as I hide it they start to return large negative numbers instead of the actual values displayed on the chart. Is this a known issue? Is there a workaround?

Thanks for the help,

Michele

3 Answers, 1 is accepted

Sort by
0
Rosko
Telerik team
answered on 15 Jun 2012, 09:15 AM
Hello Michele,

By saying "negative values", did you mean PlotAreaMouseEventArgs? I tried to reproduce this behavior but I found myself unable to do so. Is it possible to provide a small sample project where you are experiencing the problem. Also, can you share which version of the dlls are you using? I have attached the project where I tried to reproduce the issue. If you find it convenient, you can use it as a starting point.

Greetings,
Rosko
the Telerik team

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

0
Michele
Top achievements
Rank 1
answered on 15 Jun 2012, 02:36 PM
Hi Rosko,

I will paste the code in here because I am only allowed to attach images to the forum (BTW, how can you attach zip files when "Allowed extensions: .gif, .jpg, .jpeg, .png"??)

MainPage.xaml.cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Charting;
 
namespace YAxisCollabsedPlotAreaMouseLeftButtonDown
{
    public partial class MainPage : UserControl
    {
        public List<SomeInfo> Data { get; set; }
        public MainPage()
        {
            InitializeComponent();
            Data = new List<SomeInfo>();
            Random r = new Random();
 
            for (int i = 0; i < 10; i++)
            {
                Data.Add(new SomeInfo(i, r.Next(0, 10)));
            }
 
            chart.ItemsSource = Data;
        }
 
        protected void ChartArea_PlotAreaMouseLeftButtonDown(object sender, PlotAreaMouseEventArgs e)
        {
            Point currentPoint = new Point()
            {
                X = e.XValue,
                Y = e.YValue,
            };
 
            box.Text = currentPoint.Y.ToString();
        }
        public class SomeInfo
        {
            public int XVal { get; set; }
            public int YVal { get; set; }
 
            public SomeInfo(int x, int y)
            {
                this.XVal = x;
                this.YVal = y;
            }
        }
    }
}

MainPage.xaml
<UserControl x:Class="YAxisCollabsedPlotAreaMouseLeftButtonDown.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <StackPanel x:Name="LayoutRoot" Background="White">
        <TextBox x:Name="box"/>
        <telerik:RadChart x:Name="chart" BorderThickness="0">
            <telerik:RadChart.SamplingSettings>
                <telerik:SamplingSettings SamplingThreshold="0" />
            </telerik:RadChart.SamplingSettings>
            <telerik:RadChart.PaletteBrushes>
                <SolidColorBrush Color="Red" />
                <SolidColorBrush Color="Green" />
                <SolidColorBrush Color="Yellow" />
            </telerik:RadChart.PaletteBrushes>
            <telerik:RadChart.SeriesMappings>
                <telerik:SeriesMapping ItemsSource="{Binding Serie}" LegendLabel="{Binding LegendName}" >
                    <telerik:SeriesMapping.SeriesDefinition>
                        <telerik:LineSeriesDefinition ShowItemLabels="False" ShowPointMarks="False"/>
                    </telerik:SeriesMapping.SeriesDefinition>
                    <telerik:ItemMapping FieldName="XVal" DataPointMember="XValue"/>
                    <telerik:ItemMapping FieldName="YVal" DataPointMember="YValue"/>
                </telerik:SeriesMapping>
            </telerik:RadChart.SeriesMappings>
            <telerik:RadChart.DefaultView>
                <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                    <telerik:ChartDefaultView.ChartArea>
                        <telerik:ChartArea PlotAreaMouseLeftButtonDown="ChartArea_PlotAreaMouseLeftButtonDown"
                                           LegendName="ChartLegendCoManShutIn" BorderThickness="0,10,0,0" EnableAnimations="False"
                                           Padding="0,0,10,5" SmartLabelsEnabled="False">
                            <telerik:ChartArea.AxisY>
                                <telerik:AxisY Visibility="Collapsed" MinValue="0" MaxValue="10" AutoRange="False" Step="1"/>
                            </telerik:ChartArea.AxisY>
                            <telerik:ChartArea.AxisX>
                                <telerik:AxisX Title="Time"  MinValue="0" MaxValue="10" AutoRange="False" Step="1"/>
                            </telerik:ChartArea.AxisX>
                        </telerik:ChartArea>
                    </telerik:ChartDefaultView.ChartArea>
                    <telerik:ChartDefaultView.ChartLegend>
                        <telerik:ChartLegend BorderThickness="0" Header="Legend" x:Name="ChartLegendCoManShutIn"/>
                    </telerik:ChartDefaultView.ChartLegend>
                </telerik:ChartDefaultView>
            </telerik:RadChart.DefaultView>
        </telerik:RadChart>
 
    </StackPanel>
</UserControl>

I added a TextBox above the chart which contains the value of the Y position when you click on the chart.
If you run with the Y axis collabsed it give you negative numbers
If you run the application with a visible Y axis you get the correct values

Thanks for the help.

Michele
0
Rosko
Telerik team
answered on 20 Jun 2012, 08:52 AM
Hello Michelle,

RadChart is not designed to work like this. It uses the YAxis to get the position on the plot area. I can offer you a workaround which will hide the vertical axis and you will still have the right coordinates. You need to handle the SizeChanged event of RadChart and do the operations I have shown in the code snippets.

The first option will hide completely the vertical axis. It will not be possible to see even the slider for the vertical zoom and scroll. If you are not using it, I would advice you to take this option.
void chart_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var axisY = Telerik.Windows.Controls.ChildrenOfTypeExtensions.FindChildByType<AxisY2D>(this.chart);
            axisY.Width = 0;
        }

The second option will hide everything besides the slider for the vertical zoom.
void chart_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var axisY = Telerik.Windows.Controls.ChildrenOfTypeExtensions.FindChildByType<AxisY2D>(this.chart);
            var axisYGrid = axisY.FindChildByType<Grid>();
            foreach (FrameworkElement item in axisYGrid.Children)
            {
                if (!(item is RadSlider))
                    item.Width = 0;
            }
        }

P.S. In our forums attaching a .zip is unacceptable because of licensing/ security concerns. If you want to send a sample project to us, you should use the support ticketing system.

Kind regards,
Rosko
the Telerik team

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

Tags
Chart
Asked by
Michele
Top achievements
Rank 1
Answers by
Rosko
Telerik team
Michele
Top achievements
Rank 1
Share this question
or