SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

0
0

hi,
I have a series with color Red, I select it through SeriesSelectionModifier and I have code in place to change its color to Green.

But the problem I am facing is, after I deselect the series(when i click on some other part of chart), its color got reset back to Red.

Please let me know what the problem is..

I do this to change color.
ChartModifier.ParentSurface.SelectedRenderableSeries.FirstOrDefault.Stroke = newColor;

Version
latest
  • You must to post comments
0
0

This was actually converted to a support ticket, but for the benefit of the community, here is the answer:

We were able to reproduce this in a simple unit test:

   [Test]
    public void WhenSelect_SetStroke_Deselect_ShouldKeepColor()
    {
        var flrs = new FastLineRenderableSeries() {Stroke = Colors.Red};
        flrs.SelectedSeriesStyle = new Style(typeof(FastLineRenderableSeries)) { Setters = { new Setter() { Property = FastLineRenderableSeries.StrokeProperty, Value = Colors.Green}}};

        Assert.That(flrs.Stroke, Is.EqualTo(Colors.Red));

        // Apply SelectedSeriesStyle
        flrs.IsSelected = true;
        Assert.That(flrs.Stroke, Is.EqualTo(Colors.Green));

        // Deselect, should revert 
        flrs.IsSelected = false;
        Assert.That(flrs.Stroke, Is.EqualTo(Colors.Red));

        // Select, apply again
        flrs.IsSelected = true;
        Assert.That(flrs.Stroke, Is.EqualTo(Colors.Green));
        // Change color
        flrs.Stroke = Colors.Purple;
        flrs.IsSelected = false;
        Assert.That(flrs.Stroke, Is.EqualTo(Colors.Purple));
    }

Now with discussion with the team, we don’t think this is a bug, but a side effect of how we implement selection. When the series is selected the SelectedSeriesStyle is applied. When you deselect, the old style is applied.

To workaround, you can do this:

  • Handle RenderableSeries.SelectionChanged
  • On Deselection, apply your chosen color

     [Test]
    public void WhenSelect_SetStroke_Deselect_ShouldKeepColor()
    {
        var flrs = new FastLineRenderableSeries() {Stroke = Colors.Red};
        flrs.SelectedSeriesStyle = new Style(typeof(FastLineRenderableSeries)) { Setters = { new Setter() { Property = FastLineRenderableSeries.StrokeProperty, Value = Colors.Green}}};
        Color? selectedColor = null;
        flrs.SelectionChanged += (s, e) =>
        {
            if (selectedColor != null && flrs.IsSelected == false)
            {
                flrs.Stroke = selectedColor.Value;
                selectedColor = null;
            }
        };
    
        // Select
        flrs.IsSelected = true;
        Assert.That(flrs.Stroke, Is.EqualTo(Colors.Green));
        // Change color
        selectedColor = Colors.Purple;            
        // Deselect 
        flrs.IsSelected = false;
        // Check
        Assert.That(flrs.Stroke, Is.EqualTo(Colors.Purple)); // Passes
    }
    

This code works as expected.

Best regards
Andrew

  • Vibin Varghese
    Thanks Andrew. It worked!!!Do you have plans to add direction in rubberband modifier in future releases?
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.