Dynamic generation of LineSeries

8 posts, 0 answers
  1. Supriya
    Supriya avatar
    13 posts
    Member since:
    Mar 2013

    Posted 06 Apr 2013 Link to this post

    Hi,
    i have multiple y-axis in my graph which is being plotted dynamically and name associated with it comes on the basis of selection done in dropdown list.my project follows MVVM architecture. x-axis represents time.so i need to generate all y values for particular time and then add the lineseries to the Series dynamically. problem is that graph is being plotted but could not be seen.
           
    private void LoadData()
            {
                rnd = new Random();
                GraphDatas = new ObservableCollection<GraphData>();
                GraphData gd = null;
                Linearaxis = new List<LinearAxis>();
                for (int x = 0; x < 35; x++)
                {
                    foreach (WeldDataMapping _weldDataMapping in _arrayOfWeldDataMapping.Where(ab => ab.IsSelected))
                    {
                        GraphDatas = new ObservableCollection<GraphData>();
                        gd = new GraphData();
                        gd.XValue = x;

                        gd.YValue = rnd.NextDouble() * 100 ;
                        GraphDatas.Add(gd);


                        LineSeries line = new LineSeries();
                        Brush objBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(_weldDataMapping.WeldDataColor));
                        if (!Linearaxis.Any(ab => ab.Title.ToString() == _weldDataMapping.WeldDataName))
                        {

                            LinearAxis yaxis = new LinearAxis { Title = _weldDataMapping.WeldDataName, Foreground = objBrush, LineStroke = objBrush, FontSize = 15 };
                            line.VerticalAxis = yaxis;
                            Linearaxis.Add(yaxis);
                            line.Name = _weldDataMapping.WeldDataName;
                            line.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(_weldDataMapping.WeldDataColor));
                            line.DisplayName = _weldDataMapping.WeldDataName;
                            line.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "XValue" };
                            line.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "YValue" };
                            line.ItemsSource = GraphDatas;
                            //adds the lineseries to the graph.
                            _graphView.xCartesianGraph.Series.Add(line);
                        }

                        else
                        {

                            line.VerticalAxis = Linearaxis.FirstOrDefault(ab => ab.Title.ToString() == _weldDataMapping.WeldDataName);
                            line.Name = _weldDataMapping.WeldDataName;
                            line.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(_weldDataMapping.WeldDataColor));
                            line.DisplayName = _weldDataMapping.WeldDataName;
                            line.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "XValue" };
                            line.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "YValue" };
                            line.ItemsSource = GraphDatas;
                            //adds the lineseries to the graph.
                            _graphView.xCartesianGraph.Series.Add(line);
                        }
                        

                    }
                }
            }

    please provide me the solution asap.
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 10 Apr 2013 Link to this post

    Hi Supriya,

    I was unable to compile or run the code you provided because there were many elements missing.

    I have attached a simple project to demonstrate one way to manually and dynamically set up a chart with one line series. Also I strongly suggest you examine our online examples and SDK examples, so that you understand how the Telerik RadCartesianChart works, in order for you to set it up properly and so that it displays the data in the desired fashion.

    Regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 10 Apr 2013 Link to this post

    Hello,

    This SDK blog post may also be of help.

    All the best,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Senthil kumar
    Senthil kumar avatar
    21 posts
    Member since:
    Sep 2013

    Posted 27 Sep 2013 Link to this post

    currently, i am working with WPF telerik RAD control version 2013.2.724.40.i have few questions in implementing RADCartesieanChart control in my application.

    i have struck with the following implementation.
    1. Multiple Y-Axis implementation, need to show Vertical axis (Y-axis) stroke should be same as that corresponded  LineSeries's stoke.
    2. RADLegend  control is not working when the LinearAxis & X-axis are created in dynamically. could you please give sample for creating legend item in dynamically.

  6. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 02 Oct 2013 Link to this post

    Hi Senthil,

    I suggest you examine our online demos. We have many features shown in the examples and many scenarios are covered.

    1. Multiple Y-Axis implementation, need to show Vertical axis (Y-axis) stroke should be same as that corresponded  LineSeries's stoke.
    You can customize the color of the axis and labels by setting the ElementBrush property. You can use the LabelStyle property to set a style for the axis labels or use the LabelTemplate property. You can set the stroke of a LineSeries through its Stroke property.

    2. RADLegend  control is not working when the LinearAxis & X-axis are created in dynamically. could you please give sample for creating legend item in dynamically.
    By default a series does not generate legend items. You need to set the LegendSettings property in order for the series to generate a legend item.

    Regards,
    Petar Marchev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. Senthil kumar
    Senthil kumar avatar
    21 posts
    Member since:
    Sep 2013

    Posted 04 Oct 2013 Link to this post

    thanks for reply. i got answer for 2nd question (Legend setting). still iam facing issue in the first one..

    just i will explain my code here. In my code, programmatically creating the linearaxis and lineseries based on the input. multiple y-axis is applicable. so ,i want to set color of axis line & title as same lineseries/legend settings..
    // want to differentiate the y-axis based on the line series (as same as legend), but this     linearAxis.ElementBrush = lineSeries.Stroke; is not working.



     RadCartesianChart chart = sender as RadCartesianChart;
                if (chart == null)
                    return;
                ObservableCollection<HistoricalChannel> seriesModel = e.NewValue as ObservableCollection<HistoricalChannel>;

                int iCount = 0;
                LinearAxis linearAxis = chart.VerticalAxis as LinearAxis;
                List<CartesianSeries> generatedSeries = new List<CartesianSeries>();
                chart.Series.Clear();
                foreach (HistoricalChannel histriocallist in seriesModel)
                {
                    RadObservableCollection<SalesRevenue> list = histriocallist.Data;

                    LineSeries a = new LineSeries();
                    a.ItemsSource = list;
                    LineSeries lineSeries = new LineSeries();
                    string pointTemplatePath = string.Format("PointTemplate{0}", iCount + 1);
                    lineSeries.PointTemplate = chart.Resources[pointTemplatePath] as DataTemplate;

                    SeriesLegendSettings legend1 = new SeriesLegendSettings() { Title = "My Title for testing" + iCount.ToString() };
                    lineSeries.LegendSettings = legend1;
                    lineSeries.CategoryBinding = new PropertyNameDataPointBinding("Timestamp");
                    lineSeries.ValueBinding = new PropertyNameDataPointBinding("Revenue");
                    lineSeries.ItemsSource = list;

                    if (iCount != 0)
                     {
                         linearAxis = new LinearAxis();
                     }
                     if (iCount % 2 == 1)
                     {
                         if (linearAxis != null)
                         {
                             linearAxis.HorizontalLocation = AxisHorizontalLocation.Right;
                             linearAxis.Title = "Tile" + (iCount + 1).ToString();
                             linearAxis.ElementBrush = lineSeries.Stroke; //  i want to set color of axis line & title as same lineseries/legend settings..
    // want to differentiate the y-axis based on the line series (as same as legend)

    ;
                             if (iCount != 0)
                             {
                                 lineSeries.VerticalAxis = linearAxis;
                             }
                           
                         }
                     }
                     else
                     {
                         linearAxis = new LinearAxis();
                         linearAxis.HorizontalLocation = AxisHorizontalLocation.Left;
                         
                         linearAxis.Title = "Tile" + (iCount + 1).ToString();

                        // linearAxis.ElementBrush = lineSeries.Style
                         lineSeries.VerticalAxis = linearAxis;


                     }

                    chart.Series.Add(lineSeries);
                    iCount++;
    }
  8. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 09 Oct 2013 Link to this post

    Kumar,

    You need to set both properties:
    SolidColorBrush myBrush = new ....
    linearAxis.ElementBrush = myBrush;
    lineSeries.Stroke = byBrush;

    Do try this and see that all will work correctly.

    The reason that this code (linearAxis.ElementBrush = lineSeries.Stroke) does not work is that the Stroke property of the series is null by default. This is needed in order to support Stroke priorities - local series.Stroke has a higher priority than the Palette brushes, and Palette brushes have higher priority than the Stroke set from a style.

    Regards,
    Petar Marchev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  9. Senthil kumar
    Senthil kumar avatar
    21 posts
    Member since:
    Sep 2013

    Posted 09 Oct 2013 Link to this post

    Thanks for your reply. 

    In my case, i am using the default resource template value for the line series.
      lineSeries.PointTemplate = chart.Resources[pointTemplatePath] as DataTemplate;

    based on this template , the stoke colour of lineseries will be assigned to the all Lineseries. so, i couldn't take the stoke colour of the particular lineseries and assign to that particular line axis (Y-axis).

    My Requirement is, want to show style (color of title & line axis) of y-axis (line axis) as same as the that particular lineseries style.

    could you give the example for this?
Back to Top
UI for WPF is Visual Studio 2017 Ready