I’m trying to create a CustomRenderableSeries in MVVM. I’ve got my custom renderable series working fine outside of MVVM, and it seems pretty simple to wrap it with a ViewModel using the API.
However, the series isn’t displaying (Draw not getting called, and ranges not changing, so it’s not just failing to draw anything).
It’s pretty simple (and I’m going to add caching for the pens and brushes later):
public class CustomXyScatterRenderableSeriesViewModel : BaseRenderableSeriesViewModel
{
// Tell SciChart what type of RenderableSeries you want to instantiate
public override Type RenderSeriesType
{
get { return typeof(CustomXyScatterRenderableSeries); }
}
}
public sealed class CustomXyScatterRenderableSeries : CustomRenderableSeries
{
protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
{
XyzPointSeries pointSeries = renderPassData.PointSeries as XyzPointSeries;
// PointMarkers are created once and cached
var pointMarker = this.GetPointMarker();
//if (pointMarker == null)
// return;
int setCount = pointSeries.Count;
IBrush2D brush = renderContext.CreateBrush(Brushes.Red, 0.5);
IPen2D pen = renderContext.CreatePen(Colors.Transparent, false, 0, 0);
// Iterate over points collection and render point markers
for (int i = 0; i < setCount; i++)
{
double xPoint = (double)pointSeries.XValues[i];//pointSeries[i].X;
double yPoint = (double)pointSeries.YValues[i];//pointSeries[i].Y;
double zPoint = (int)pointSeries.ZPoints[i];
// Get coordinates for X,Y data values
var x1 = (int)renderPassData.XCoordinateCalculator.GetCoordinate(xPoint);
var y1 = (int)renderPassData.YCoordinateCalculator.GetCoordinate(yPoint);
var z1 = (int)zPoint+2;
//var pointMarkerRect = new Rect(0, 0, pointMarker.PixelWidth, pointMarker.PixelWidth);
//double xOffset = pointMarkerRect.Width / 2;
//double yOffset = pointMarkerRect.Height / 2;
// Draw PointMarkers
renderContext.DrawEllipse(pen, brush, new Point(x1, y1), z1 * 2, z1 * 2); //(new Rect(x1 - xOffset, y1 - yOffset, pointMarkerRect.Width, pointMarkerRect.Height), pointMarker, pointMarkerRect);
}
brush.Dispose();
pen.Dispose();
}
}
When directly, all is good:
<s:SciChartSurface x:Name="SciChartSurface"
DebugWhyDoesntSciChartRender="True"
GridLinesPanelStyle="{StaticResource GridLinesPanelStyle}"
DataContext="{Binding ElementName=userControl}"
ViewportManager="{Binding ViewportManager}"
ChartTitle="{Binding Title}">
<s:SciChartSurface.RenderSurface>
<s3D:Direct3D10RenderSurface />
</s:SciChartSurface.RenderSurface>
<s:SciChartSurface.RenderableSeries>
<helpers:CustomXyScatterRenderableSeries DataSeries="{Binding Data}" />
</s:SciChartSurface.RenderableSeries>
<s:SciChartSurface.XAxis>
<s:NumericAxis AxisTitle="{Binding XAxisLabel}" LabelProvider="{StaticResource SINumericLabelProvider}"/>
</s:SciChartSurface.XAxis>
<s:SciChartSurface.YAxis>
<s:NumericAxis AxisTitle="{Binding YAxisLabel}" LabelProvider="{StaticResource SINumericLabelProvider}"/>
</s:SciChartSurface.YAxis>
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<s:MouseWheelZoomModifier x:Name="mouseWheelZoomModifier" />
<s:RubberBandXyZoomModifier ExecuteOn="MouseRightButton" IsAnimated="True" />
<s:ZoomPanModifier />
<s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick" />
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
</s:SciChartSurface>
But when using the View Model, it fails to display:
<s:SciChartSurface x:Name="SciChartSurface"
DebugWhyDoesntSciChartRender="True"
GridLinesPanelStyle="{StaticResource GridLinesPanelStyle}"
DataContext="{Binding ElementName=userControl}"
ViewportManager="{Binding ViewportManager}"
ChartTitle="{Binding Title}"
RenderableSeries="{s:SeriesBinding Series}">
<s:SciChartSurface.RenderSurface>
<s3D:Direct3D10RenderSurface />
</s:SciChartSurface.RenderSurface>
....
</s:SciChartSurface>
I’m not sure what I’m doing wrong, as there doesn’t seem to be much more to it!
Edit: More info, in the code behind, I’m binding to this data for testing:
public XyzDataSeries<float, float, int> Data { get; set; }
public ObservableCollection<IRenderableSeriesViewModel> Series { get; set; }
public LineChart()
{
this.DataContext = this;
Data = new XyzDataSeries<float, float, int>();
Data.Append(50, 50, 10);
Data.Append(100, 100, 15);
Series = new ObservableCollection<IRenderableSeriesViewModel>();
Series.Add(new CustomXyScatterRenderableSeriesViewModel() { DataSeries = Data });
InitializeComponent();
}
- Ken Hobbs asked 8 years ago
- last edited 8 years ago
- You must login to post comments
Well, that’ll teach me to read things properly in future. Adding the style made things work fine:
<ResourceDictionary>
<!-- Merged Dictionary is required for BasedOn attribute -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/SciChart.Charting;component/Themes/Default.xaml"/>
</ResourceDictionary.MergedDictionaries>
<helpers:SINumericLabelProvider x:Key="SINumericLabelProvider"/>
<!-- The style for the custom renderable series -->
<Style TargetType="helpers:CustomXyScatterRenderableSeries"
BasedOn="{StaticResource MvvmDefaultRenderableSeriesStyle}">
</Style>
</ResourceDictionary>
- Ken Hobbs answered 8 years ago
- last edited 8 years ago
-
Great! Glad you found it. I was going to comment the other day, then got distracted by other work … I’m also glad the docs are proving useful! :) Best regards, Andrew
- You must login to post comments
Please login first to submit.