Using Oxyplot, how would I remove an item from a given ColumnSeries?
Given the code which is the example provided in the library itself (with a small modification), as well as a Delete event of some sort (which I could figure out myself) how would I remove an item (column) from the graph?
If I simply remove the item from the bar.Items list, the Label won't dissaper. Removing it from the tmp.Axes[0].ActualLabels (which is the CategoryAxis) won't "refresh" the view, and the Label remains there. Is there any solution for this situation? I've managed to do it with Line and Pie Graphs, but I'm struggling with the Column one.
Code-behind for building the Graph:
namespace ColumnSeriesDemo
{
using System.Collections.ObjectModel;
using System.Windows;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using WpfExamples;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
[Example("Shows column series.")]
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
// Create some data
this.Items = new Collection<Item>
{
new Item {Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19},
new Item {Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9},
new Item {Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29}
};
// Create the plot model
var tmp = new PlotModel { Title = "Column series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical };
// Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis.
tmp.Axes.Add(new CategoryAxis { ItemsSource = this.Items, LabelField = "Label" });
tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0 });
// Add the series, note that the BarSeries are using the same ItemsSource as the CategoryAxis.
ColumnSeries bar = new ColumnSeries();
tmp.Series.Add(bar);
bar.Items.Add(new ColumnItem { Color = OxyPlot.OxyColors.Yellow, Value = this.Items[0].Value3, CategoryIndex = 0 });
bar.Items.Add(new ColumnItem { Color = OxyPlot.OxyColors.Green, Value = this.Items[0].Value2, CategoryIndex = 2 });
bar.Items.Add(new ColumnItem { Color = OxyPlot.OxyColors.Red, Value = this.Items[0].Value1, CategoryIndex = 3 });
this.Model1 = tmp;
this.DataContext = this;
}
public Collection<Item> Items { get; set; }
public PlotModel Model1 { get; set; }
}
public class Item
{
public string Label { get; set; }
public double Value1 { get; set; }
public double Value2 { get; set; }
public double Value3 { get; set; }
}
}