Index: Core/Components/src/Core.Components.Charting/IChart.cs =================================================================== diff -u -reb44708823d5479991162f63376ae85dd944e513 -r16f0202ea76565e235a73eae6637b3ca03e9c3df --- Core/Components/src/Core.Components.Charting/IChart.cs (.../IChart.cs) (revision eb44708823d5479991162f63376ae85dd944e513) +++ Core/Components/src/Core.Components.Charting/IChart.cs (.../IChart.cs) (revision 16f0202ea76565e235a73eae6637b3ca03e9c3df) @@ -25,14 +25,6 @@ ICollection Data { get; set; } /// - /// Sets the visibility of a series in this . - /// - /// The to set the visibility for. - /// A boolean value representing the new visibility. - /// Thrown when is null. - void SetVisibility(ChartData data, bool visibility); - - /// /// Sets the position of the amongst the other data of the . /// /// The to change the position for. Index: Core/Components/src/Core.Components.OxyPlot.Forms/BaseChart.cs =================================================================== diff -u -reb44708823d5479991162f63376ae85dd944e513 -r16f0202ea76565e235a73eae6637b3ca03e9c3df --- Core/Components/src/Core.Components.OxyPlot.Forms/BaseChart.cs (.../BaseChart.cs) (revision eb44708823d5479991162f63376ae85dd944e513) +++ Core/Components/src/Core.Components.OxyPlot.Forms/BaseChart.cs (.../BaseChart.cs) (revision 16f0202ea76565e235a73eae6637b3ca03e9c3df) @@ -51,17 +51,6 @@ } } - public void SetVisibility(ChartData data, bool visibility) - { - if (data == null) - { - throw new ArgumentNullException("data", "Cannot set visibility of a null serie."); - } - data.IsVisible = visibility; - series.First(t => ReferenceEquals(t.Item1, data)).Item2.IsVisible = visibility; - view.Invalidate(); - } - public void SetPosition(ChartData data, int position) { if (data == null) @@ -142,13 +131,18 @@ /// The of to set. private void SetData(ICollection dataCollection) { + foreach (var seriesTuple in series) + { + seriesTuple.Item1.Detach(this); + } series.Clear(); if (dataCollection != null) { foreach (var data in dataCollection) { AddDataAsSeries(data); + data.Attach(this); } } @@ -257,6 +251,10 @@ public void UpdateObserver() { + foreach (var serieTuple in series) + { + serieTuple.Item2.IsVisible = serieTuple.Item1.IsVisible; + } view.InvalidatePlot(true); } } Index: Core/Components/test/Core.Components.OxyPlot.Forms.Test/BaseChartTest.cs =================================================================== diff -u -reb44708823d5479991162f63376ae85dd944e513 -r16f0202ea76565e235a73eae6637b3ca03e9c3df --- Core/Components/test/Core.Components.OxyPlot.Forms.Test/BaseChartTest.cs (.../BaseChartTest.cs) (revision eb44708823d5479991162f63376ae85dd944e513) +++ Core/Components/test/Core.Components.OxyPlot.Forms.Test/BaseChartTest.cs (.../BaseChartTest.cs) (revision 16f0202ea76565e235a73eae6637b3ca03e9c3df) @@ -110,50 +110,6 @@ } [Test] - public void SetVisibility_SerieNotOnChart_ThrowsInvalidOperationException() - { - // Setup - var chart = new BaseChart(); - var pointData = new PointData(new Collection>()); - - // Call - TestDelegate test = () => chart.SetVisibility(pointData, true); - - // Assert - Assert.Throws(test); - } - - [Test] - [TestCase(true)] - [TestCase(false)] - public void SetVisibility_SerieOnChart_SetsDataVisibility(bool visibility) - { - // Setup - var chart = new BaseChart(); - var pointData = new PointData(new Collection>()); - chart.Data = new ChartData[] { pointData }; - - // Call - chart.SetVisibility(pointData, visibility); - - // Assert - Assert.AreEqual(visibility, pointData.IsVisible); - } - - [Test] - public void SetVisibility_ForNull_ThrowsArgumentNullException() - { - // Setup - var chart = new BaseChart(); - - // Call - TestDelegate test = () => chart.SetVisibility(null, true); - - // Assert - Assert.Throws(test); - } - - [Test] public void SetPosition_DataNull_ThrowsArgumentNullException() { // Setup Index: Core/Plugins/src/Core.Plugins.OxyPlot/Legend/ChartDataNodePresenter.cs =================================================================== diff -u -r79c9b71fa0d32c90d568eafea03601edd9578155 -r16f0202ea76565e235a73eae6637b3ca03e9c3df --- Core/Plugins/src/Core.Plugins.OxyPlot/Legend/ChartDataNodePresenter.cs (.../ChartDataNodePresenter.cs) (revision 79c9b71fa0d32c90d568eafea03601edd9578155) +++ Core/Plugins/src/Core.Plugins.OxyPlot/Legend/ChartDataNodePresenter.cs (.../ChartDataNodePresenter.cs) (revision 16f0202ea76565e235a73eae6637b3ca03e9c3df) @@ -42,7 +42,9 @@ public override void OnNodeChecked(TreeNode node) { - ((LegendTreeView) TreeView).Chart.SetVisibility((ChartData)node.Tag, node.Checked); + var chartData = ((ChartData)node.Tag); + chartData.IsVisible = node.Checked; + chartData.NotifyObservers(); } } } \ No newline at end of file