Applying a Brush to a ScatterPointSeries I create at runtime

3 posts, 0 answers
  1. Robert
    Robert avatar
    5 posts
    Member since:
    Jan 2013

    Posted 11 Feb 2014 Link to this post


    I'm creating a ScatterPointSeries at runtime and have had no problem adding it to my ChartView. I want to do this multiple times though so I want to apply a different brush to each.

    ScatterPointSeries sps = new ScatterPointSeries();
    brush = Brushes.Red; // This will be dynamic
    sps.ItemsSource = source;
    sps.XValueBinding = new PropertyNameDataPointBinding() { PropertyName = XPath };
    sps.YValueBinding = new GenericDataPointBinding<T, float>() { ValueSelector = Function };


    How can I apply the brush to the ScatterPointSeries points? I've experimented with a datatemplate, but this will only let me style all the scatterpoints to use the same brush.


  2. Robert
    Robert avatar
    5 posts
    Member since:
    Jan 2013

    Posted 11 Feb 2014 in reply to Robert Link to this post

    I was hoping for something along the lines of a Stroke property which is exposed by other series like ScatterLineSeries.
  3. Martin Ivanov
    Martin Ivanov avatar
    1451 posts

    Posted 14 Feb 2014 Link to this post

    Hello Robert,

    There are several ways to achieve your requirement. You could change the color of the series by using any of our Palettes. Here is an example how you could set a palette in code: 
    this.Chart.Palette = ChartPalettes.Windows8;
    Another option would be to create a custom palette where you could define your colors. Here is an example in code:
    var customPalette = new ChartPalette();
    var entryCollection = new PaletteEntryCollection
        new PaletteEntry(Brushes.DarkOliveGreen),
        new PaletteEntry(Brushes.DarkOrange),
        new PaletteEntry(Brushes.DarkTurquoise),
        new PaletteEntry(Brushes.LightGoldenrodYellow),
    entryCollection.SeriesFamily = "Point";
    Chart.Palette = customPalette;

    You could also set the DefaultVisualStyle property of the series:
    ScatterPointSeries sps = new ScatterPointSeries();
    Brush brush = Brushes.Red;
    Style style = new Style(typeof(Path));
    style.Setters.Add(new Setter(Path.FillProperty, brush));
    sps.DefaultVisualStyle = style;
    Also please note that it is better to create the style in XAML instead of in code behind.

    I attached a sample project with the last mentioned approach.


    Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

Back to Top