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

Scatter Series by category?

12 Answers 67 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 08 Jan 2014, 07:00 PM
Is it possible to create a Scatter Series that has a custom category as an axis?

For example, I'd like to create a scatter plot that has name of companies on the X-axis and their related money values on the Y-axis.

Is there any way to do this?

12 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 10 Jan 2014, 12:56 PM
Hi Kevin,

Thank you for contacting us.

In your scenario you can use BarSeries and edit the PointTemplate of the series. I have attached a runnable sample application that demonstrates how to do that.

For the next official release (Q1 2014) planned for mid-February we will introduce several new types of series, including PointSeries that are analogous to the ScatterSeries but use one categorical axis.

I hope this was useful. Please, do not hesitate to contact us if you have further questions.


Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Erik
Top achievements
Rank 1
answered on 20 Feb 2014, 12:26 PM
I was just looking for the PointSeries for categorical axis. Has it been released yet?

Thanks,
Erik
0
Rosy Topchiyska
Telerik team
answered on 21 Feb 2014, 11:46 AM
Hello Erik,

Thank you for contacting us.

We will release the next official version of the controls (Q1 2014) by the end of the next week.

Let us know if you have further questions.

Regards,
Rositsa Topchiyska
Telerik
0
Erik
Top achievements
Rank 1
answered on 21 Feb 2014, 12:21 PM
Great, looking forward to it!
0
Erik
Top achievements
Rank 1
answered on 28 Feb 2014, 03:13 PM
Hi,

I have now upgraded to the latest release, and found the PointSeries! However, I get an error in my custom CategoricalSeriesDescriptor:

public class CustomChartSeriesDescriptor : CategoricalSeriesDescriptor
{
    protected override ChartSeries CreateInstanceCore(object context)
    {
        var series = base.CreateInstanceCore(context); //this is where exception happens

Exception: 
An exception of type 'System.InvalidOperationException' occurred in Telerik.UI.Xaml.Chart.DLL but was not handled in user code
Additional information: Expected Categorical series instance.


This is when I set the TypePath in my CustomChartSeriesDescriptor to the type PointSeries. It works when I change that to for example BarSeries. Am I using the incorrect type?

Regards,
Erik
0
Ivaylo Gergov
Telerik team
answered on 03 Mar 2014, 08:11 AM
Hi Erik,

Currently the CategoricalSeriesDescriptor works with CategoricalSeries, but the PointSeries is of type CategoricalSeriesBase(the CategoricalSeries class exposes logic for CombineMode which is not relevant for the PointSeries). We will fix this for our next release.
For now, as a workaround I can suggest that you use the logic from the base.CreateInstanceCore method and replace the CategoricalSeries class with CategoricalSeriesBase class.
For your convenience I have attached a modified project(based on the project in the following forum thread).

I hope this works for you. Let me know should you have any questions or suggestions. Also, I have updated your Telerik points for the valuable feedback.



Regards,
Ivaylo Gergov
Telerik
0
Erik
Top achievements
Rank 1
answered on 03 Mar 2014, 08:56 AM
Hi Ivaylo,

Thanks, that works fine!

Regards,
Erik
0
Erik
Top achievements
Rank 1
answered on 04 Mar 2014, 10:45 AM
Hi Ivaylo,

I have a follow-up question. I find the documentation quite difficult to follow for some simple configuration.

In my CategoricalSeriesDescriptor (code above) I set the LineSeries Stroke color based on the data item:

if (series is LineSeries)
            {
                var lineSeries = ((LineSeries)series);
                lineSeries.VerticalAxis = chartDataItemsViewModel.VerticalAxis;
                lineSeries.Stroke = chartDataItemsViewModel.SeriesBrush;
            }

However, now I'm looking for the property to set the PointSeries "PointBrush", the color of the point in the same manner, but I cannot find a property for it. Only PointSize. What am I missing?

Regards,
Erik

0
Ivaylo Gergov
Telerik team
answered on 04 Mar 2014, 12:26 PM
Hi Erik,

The PointSeries is similar to the BarSeries and supports DefaultVisualStyle property that allows to change the appearance of the datapoints. Here's an example: 

Style style = new Style(typeof(Path));
style.Setters.Add(new Setter(Path.FillProperty, new SolidColorBrush(Colors.Yellow)));
style.Setters.Add(new Setter(Path.StrokeProperty, new SolidColorBrush(Colors.Red)));
pointSeries.DefaultVisualStyle = style;

As you can see, by default, the datapoints are represented by a Path. The Fill and the Stroke properties are not exposed in the PointSeries class because if you change the PointTemplate and use a Button, for example, these properties cannot be interpreted.
Also, we will take into account the note about the documentation and we will add this configuration in the example.

I hope this is useful.

Regards,
Ivaylo Gergov
Telerik
0
Erik
Top achievements
Rank 1
answered on 04 Mar 2014, 01:42 PM
Hi,

Unfourtunately it does not seem to work for me. My code:

public class CustomChartSeriesDescriptor : CategoricalSeriesDescriptor
{
    protected override ChartSeries CreateInstanceCore(object context)
    {
        var series = CreateDefaultInstance(context) as CategoricalSeriesBase;
        if (series == null)
        {
            throw new InvalidOperationException("Expected Categorical series instance.");
        }
 
        var valuePath = ValuePath;
        if (!string.IsNullOrEmpty(valuePath))
        {
            series.ValueBinding = new PropertyNameDataPointBinding(valuePath);
        }
 
        var categoryPath = CategoryPath;
        if (!string.IsNullOrEmpty(categoryPath))
        {
            series.CategoryBinding = new PropertyNameDataPointBinding(categoryPath);
        }
 
        var chartDataItemsViewModel = ((ChartDataItemsViewModel)context);
        if (series is LineSeries)
        {
            var lineSeries = ((LineSeries)series);
            lineSeries.VerticalAxis = chartDataItemsViewModel.VerticalAxis;
            lineSeries.Stroke = chartDataItemsViewModel.SeriesBrush;
        }
        else if (series is PointSeries)
        {
            var pointSeries = ((PointSeries)series);
            pointSeries.VerticalAxis = chartDataItemsViewModel.VerticalAxis;
            var style = new Style(typeof(Path));
            //style.Setters.Add(new Setter(Path.FillProperty, chartDataItemsViewModel.SeriesBrush));
            //style.Setters.Add(new Setter(Path.StrokeProperty, chartDataItemsViewModel.SeriesBrush));
            style.Setters.Add(new Setter(Path.FillProperty, new SolidColorBrush(Colors.Yellow)));
            style.Setters.Add(new Setter(Path.StrokeProperty, new SolidColorBrush(Colors.Red)));
            pointSeries.DefaultVisualStyle = style;
            return pointSeries;
        }
        return series;
    }
}

And in the XAML:

<telerikChart:RadCartesianChart.Resources>
    <Style TargetType="telerikChart:LineSeries">
        <Setter Property="Transitions" Value="{x:Null}"/>
        <Setter Property="CombineMode" Value="None"/>
        <Setter Property="StrokeThickness" Value="3"/>
        <Setter Property="PointTemplate" Value="{StaticResource LinePoinTemplate}"/>
    </Style>
    <Style TargetType="telerikChart:PointSeries">
        <Setter Property="Transitions" Value="{x:Null}"/>
    </Style>
</telerikChart:RadCartesianChart.Resources>
<telerikChart:RadCartesianChart.SeriesProvider>
    <telerikChart:ChartSeriesProvider x:Name="provider"
        Source="{Binding Chart.ChartData}">
        <telerikChart:ChartSeriesProvider.SeriesDescriptors>
            <common:CustomChartSeriesDescriptor
                CategoryPath="Time"
                ValuePath="ValueAsDouble"
                ItemsSourcePath="Measurements" TypePath="SeriesType">
            </common:CustomChartSeriesDescriptor>
        </telerikChart:ChartSeriesProvider.SeriesDescriptors>
    </telerikChart:ChartSeriesProvider>
</telerikChart:RadCartesianChart.SeriesProvider>

It still gives me the default colors of the point series.

Thanks for your quick feedback!
Regards Erik
0
Erik
Top achievements
Rank 1
answered on 05 Mar 2014, 09:38 AM
Hi,

I solved this using a DataTemplate for the PointTemplate like I did for the LineSeries, and binding with a converter to the DataItem. So no need for this  feature right now.

Thanks.

Regards,
Erik
0
Ivaylo Gergov
Telerik team
answered on 05 Mar 2014, 10:09 AM
Hello,

If the RadChart has a ChartPalette applied, the DefaultVisualStyle of the series is ignored. However if you wish to use both ChartPalette and apply custom colors when needed, you can use the approach that you have already found.

Please let us know if this is the case.

Regards,
Ivaylo Gergov
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how DevCraft solves your top-5 .NET challenges. Reserve your seat now!

Tags
Chart for XAML
Asked by
Kevin
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Erik
Top achievements
Rank 1
Ivaylo Gergov
Telerik team
Share this question
or