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

ConvertPhysicalUnitsToData return wrong value

4 Answers 78 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Yonghan
Top achievements
Rank 1
Yonghan asked on 16 Jan 2011, 06:41 AM
Hi,

AxisX.ConvertPhysicalUnitsToData() and AxisY.ConvertPhysicalUnitsToData() are both return wrong value.

working:
      RadChart1.DefaultView.ChartArea.AxisX.Visibility = Visibility.Visible;
      RadChart1.DefaultView.ChartArea.AxisY.Visibility = Visibility.Visible;
      RadChart1.DefaultView.ChartArea.Legend.Visibility = Visibility.Collapsed;

other cases are returned wrong value.

How do I know calculated X,Y values?
If I added movable vertical GridLine annotation, how do I know GridLine's Y value when it moved?
and I'm using RadControls for Silverlight Q3 2010 SP1.

here is my test code.
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;
using System.Collections.ObjectModel;
 
namespace Grouping_DateTime
{
  public partial class MainPage : UserControl
  {
    static ObservableCollection<Setpoint> setpoints = new ObservableCollection<Setpoint>();
 
    public MainPage()
    {
      InitializeComponent();
 
      getSetpointCollection();
 
      SeriesMapping sm2 = new SeriesMapping();
      sm2.SeriesDefinition = new LineSeriesDefinition() { ShowPointMarks = false, ShowItemToolTips = true };
      sm2.SeriesDefinition.Appearance.StrokeThickness = 1.5;
      sm2.ItemMappings.Add(new ItemMapping("Score", DataPointMember.YValue));
      sm2.ItemMappings.Add(new ItemMapping("Time", DataPointMember.XValue));
      sm2.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("SiteID"));
 
      RadChart1.DefaultView.ChartArea.Legend.Visibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.Padding = new Thickness(0);
      RadChart1.DefaultView.ChartArea.Margin = new Thickness(0);
      RadChart1.DefaultView.ChartArea.EnableAnimations = false;
      RadChart1.DefaultView.ChartArea.EnableTransitionAnimations = false;
      RadChart1.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.None;
 
      RadChart1.DefaultView.ChartArea.ItemToolTipOpening += OnItemToolTipOpening;
 
      RadChart1.DefaultView.ChartArea.AxisY.AutoRange = true;
      RadChart1.DefaultView.ChartArea.AxisY.ExtendDirection = AxisExtendDirection.Both;
      RadChart1.DefaultView.ChartArea.AxisY.Visibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.AxisY.MajorTicksVisibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.AxisY.PlotAreaAxisVisibility = Visibility.Collapsed;
 
      RadChart1.DefaultView.ChartArea.AxisX.AutoRange = false;
      RadChart1.DefaultView.ChartArea.AxisX.AddRange(-2, 16, 1);
      RadChart1.DefaultView.ChartArea.AxisX.ShouldRoundMinValueOnZoom = true;
      RadChart1.DefaultView.ChartArea.AxisX.ShouldScaleStepOnZoom = true;
      RadChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "#VAL{F1}";
      RadChart1.DefaultView.ChartArea.AxisX.TicksDistance = 0;
      RadChart1.DefaultView.ChartArea.AxisX.IsZeroBased = true;
      RadChart1.DefaultView.ChartArea.AxisX.Visibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Normal;
      RadChart1.DefaultView.ChartArea.AxisX.MajorGridLinesVisibility = Visibility.Visible;
      RadChart1.DefaultView.ChartArea.AxisX.MajorTicksVisibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.AxisX.MinorGridLinesVisibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.AxisX.StripLinesVisibility = Visibility.Collapsed;
      RadChart1.DefaultView.ChartArea.AxisX.PlotAreaAxisVisibility = Visibility.Collapsed;
 
      this.RadChart1.SeriesMappings.Add(sm2);
      this.RadChart1.ItemsSource = setpoints;
    }
 
    void OnItemToolTipOpening(ItemToolTip2D tooltip, ItemToolTipEventArgs e)
    {
      ChartArea chartArea = RadChart1.DefaultView.ChartArea;
      Point physical = e.MouseData.GetPosition(chartArea);
      double x = chartArea.AxisX.ConvertPhysicalUnitsToData(physical.X);
      double y = chartArea.AxisY.ConvertPhysicalUnitsToData(physical.Y);
      tooltip.Content = string.Format("X: {0:0.0} Y={1:0.0}", x, y);
    }
     
    public class Setpoint
    {
      private double time;
      private double score;
      private string siteID;
 
      public double Time
      {
        get { return time; }
        set
        {
          if (value != time)
          {
            time = value;
          }
        }
      }
 
      public double Score
      {
        get { return score; }
        set
        {
          if (value != score)
          {
            score = value;
          }
        }
      }
 
      public string SiteID
      {
        get { return siteID; }
        set
        {
          if (value != siteID)
          {
            siteID = value;
          }
        }
      }
    }
 
    private void getSetpointCollection()
    {
      string id = "2010-12-01 09:00";
      setpoints.Add(new Setpoint { Time = -2.0, Score = 1150.0, SiteID = id });
      setpoints.Add(new Setpoint { Time = 0, Score = 50.0, SiteID = id });
      setpoints.Add(new Setpoint { Time = 5, Score = 100.0, SiteID = id });
      setpoints.Add(new Setpoint { Time = 7, Score = 150, SiteID = id });
      setpoints.Add(new Setpoint { Time = 9, Score = 200, SiteID = id });
      setpoints.Add(new Setpoint { Time = 11, Score = 300, SiteID = id });
      setpoints.Add(new Setpoint { Time = 13, Score = 350, SiteID = id });
      setpoints.Add(new Setpoint { Time = 16.0, Score = 350, SiteID = id });
    }
  }
}


Thanks,

4 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 19 Jan 2011, 09:58 AM
Hello Yonghan,

It is the expected behavior for ConvertPhysicalUnitsToData() to not return the actual values when the X and Y axes are collapsed , since it uses them as a reference. Another way to make the returned value more accurate would be to use the PlotArea, instead of the ChartArea :

private Panel PlotAreaPanel
   {
       get
       {
           return this.RadChart1.DefaultView.ChartArea.ChildrenOfType<ClipPanel>()[0] as Panel;
       }
   }
  
   void OnItemToolTipOpening(ItemToolTip2D tooltip, ItemToolTipEventArgs e)
   {
     ChartArea chartArea = RadChart1.DefaultView.ChartArea;
     Point physical = e.MouseData.GetPosition(PlotAreaPanel);
     double x = chartArea.AxisX.ConvertPhysicalUnitsToData(physical.X);
     double y = chartArea.AxisY.ConvertPhysicalUnitsToData(physical.Y);
     tooltip.Content = string.Format("X: {0:0.0} Y={1:0.0}", x, y);
   }

For more information and code samples, please refer to Yavor Ivanov's blog post regarding the newly exposed interactivity API.

Greetings,
Nikolay
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Yonghan
Top achievements
Rank 1
answered on 19 Jan 2011, 10:42 AM
Hi, Nikolay

Thank you for your answer.
And I've checked Yavor Ivanov's blog post , it was a good article.
But when I collapsed axises, then X & Y values aren't calculated.

thanks.
0
Nikolay
Telerik team
answered on 24 Jan 2011, 08:47 AM
Hello Yonghan,

In order to use ConvertPhysicalUnitsToData(), it is required that the axes are visible, as it is not possible to calculate the Data points without the information from them. Please, excuse us for the inconvenience caused.

Kind regards,
Nikolay
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Yonghan
Top achievements
Rank 1
answered on 27 Jan 2011, 06:49 PM
Hi, Nikolay

I just figured out, how to ConvertPhysicalUnitsToData without axises visibility.
I cahanged AxisLineStyle!
       TargetType="Line">
  <Setter Property="Stroke" Value="Transparent"/>
  <Setter Property="StrokeThickness" Value="0"/>
</Style>

hide AxisLabels, MinorTicks
var axisY = new AxisY
{
  AxisName = dataSeries.LegendLabel,
  AutoRange = true,
  ExtendDirection = AxisExtendDirection.Both,
  Visibility = Visibility.Visible,
  MajorGridLinesVisibility = Visibility.Collapsed,
  MajorTicksVisibility = Visibility.Collapsed,
  StripLinesVisibility = Visibility.Collapsed,
  PlotAreaAxisVisibility = Visibility.Collapsed,
  PlotAreaAxisLabelsVisibility = Visibility.Collapsed,
  MinorTicksVisibility = Visibility.Collapsed,
  AxisLabelsVisibility = Visibility.Collapsed,      
};
axisY.AxisStyles.AxisLineStyle = AxisLineStyle;

Then, it's work perfectly!!
Now, I can insert data where I want.

Regards,
Yonghan
Tags
Chart
Asked by
Yonghan
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Yonghan
Top achievements
Rank 1
Share this question
or