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

Create Chart with Code

3 Answers 34 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Yong Gu Kang
Top achievements
Rank 1
Iron
Yong Gu Kang asked on 21 Feb 2014, 02:41 PM
Hi telerik,

I have to create chart with code not xaml having LogarithmicAxis and LinearAxis, but can't display series successfully
and don't know  what is my mistake, though I refered your sample code in this forum and your doc as well.
My code snippet is as follows;
private RadCartesianChart GetChart()
     {
         RadCartesianChart cartChart = new RadCartesianChart();
 
         cartChart.HorizontalAxis = new LinearAxis() { Maximum = 50, Minimum = 17, MajorStep = 3 };
         cartChart.VerticalAxis = new LogarithmicAxis() { LogarithmBase = 10, Minimum = 1000, Maximum = 1000000 };
 
         LineSeries lineSeries = new LineSeries() { ShowLabels = true };
         // lineSeries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "Age" };
         lineSeries.CategoryBinding = new GenericDataPointBinding<CordXy, double>() { ValueSelector = value => value.Age };
         lineSeries.ValueBinding = new GenericDataPointBinding<CordXy, double>() { ValueSelector = cord => cord.Num };
         // lineSeries.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Num" };
         lineSeries.ItemsSource = CordXy.GetFollicleList();
 
         cartChart.Series.Add(lineSeries);
 
         DoubleCollection aray = new DoubleCollection(new double[] {1,1});
 
         cartChart.Annotations.Add(
                 new CartesianCustomLineAnnotation
                 {
                     HorizontalFrom = 35,
                     HorizontalTo = 35,
                     VerticalFrom = 0,
                     VerticalTo = 1000000,
 
                     Stroke = new SolidColorBrush(Colors.Blue),
                     StrokeThickness = 2,
                     DashArray = aray
                 });
         return cartChart;
     }
 }
 
 public class CordXy
 {
     public double Age { get; set; }
     public double Num { get; set; }
 
     public static ObservableCollection<CordXy> GetFollicleList()
     {
         var result = new ObservableCollection<CordXy>();
         for (int i = 0; i < 33; i++)
         {
             var add = new CordXy();
             add.Age = i + 18;
             add.Num = Math.Pow(10, (5.717 - 0.00019 * Math.Pow(add.Age, 2.452)));
             result.Add(add);
         }
         return result;
     }
 }

As you see, x-axis is linear which shows age of person and y-axis shows calculated value as logarithmic.
I think I did correct as you told with your sample and doc, but no luck.
Pls see my attached image and advise me what I made a mistake.

Thank you in advance.

RGDS
HK.Lee






3 Answers, 1 is accepted

Sort by
0
Accepted
Milena
Telerik team
answered on 26 Feb 2014, 09:46 AM
Hello Kang,

You can combine different type of series with the appropriate type of axis – more about the possible combinations you can see in our Series and Axes article. In your RadChartView you have Logarithmic Axis and Linear Axis, which required using of Scatter Series, that can be plotted on two linear axes unlike the other series (like Line Series ) which are always plotted on a categorical and a linear or another categorical axis. So, if you change the Line Series with Scatter Series, they will be displayed successfully.

For your convenience I’m sending you a sample project (following your code), where I’ve used a ScatterLineSeries.

I hope this information helps you.


Regards,
Milena
Telerik
0
Pavel R. Pavlov
Telerik team
answered on 26 Feb 2014, 09:59 AM
Hello Kang,

You can combine different type of series with the appropriate type of axis – more about the possible combinations you can see in our Series and Axes article. In your RadChartView you have Logarithmic Axis and Linear Axis, which required using of Scatter Series, that can be plotted on two linear axes unlike the other series (like Line Series ) which are always plotted on a categorical and a linear or another categorical axis. So, if you change the Line Series with Scatter Series, they will be displayed successfully.

For your convenience I’m sending you a sample project (following your code), where I’ve used a ScatterLineSeries.

I hope this information helps you.


Regards,
Pavel R. Pavlov
Telerik
0
Yong Gu Kang
Top achievements
Rank 1
Iron
answered on 03 Mar 2014, 05:38 AM
Thank you Milena,
It works great and your kind explanation was a great help.

RGDS
Kang
Tags
ChartView
Asked by
Yong Gu Kang
Top achievements
Rank 1
Iron
Answers by
Milena
Telerik team
Pavel R. Pavlov
Telerik team
Yong Gu Kang
Top achievements
Rank 1
Iron
Share this question
or