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

Applying a Brush to a ScatterPointSeries I create at runtime

2 Answers 61 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 11 Feb 2014, 01:39 PM
Hi,

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 };

Chart.Series.Add(sps);


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.

Thanks,

Rob

2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 11 Feb 2014, 01:40 PM
I was hoping for something along the lines of a Stroke property which is exposed by other series like ScatterLineSeries.
0
Martin Ivanov
Telerik team
answered on 14 Feb 2014, 09:33 AM
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";
customPalette.SeriesEntries.Add(entryCollection);
 
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.

Regards,
Martin
Telerik

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).

Tags
ChartView
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or