c# - Remove item from ColumnSeries -


using oxyplot, how remove item given columnseries?

given code example provided in library (with small modification), delete event of sort (which figure out myself) how remove item (column) graph?

if remove item bar.items list, label won't dissaper. removing tmp.axes[0].actuallabels (which categoryaxis) won't "refresh" view, , label remains there. there solution situation? i've managed line , pie graphs, i'm struggling column one.

code-behind building graph:

namespace columnseriesdemo {     using system.collections.objectmodel;     using system.windows;      using oxyplot;     using oxyplot.axes;     using oxyplot.series;      using wpfexamples;      /// <summary>     /// interaction logic mainwindow.xaml     /// </summary>     [example("shows column series.")]     public partial class mainwindow : window     {         public mainwindow()         {             this.initializecomponent();              // create 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 plot model             var tmp = new plotmodel { title = "column series", legendplacement = legendplacement.outside, legendposition = legendposition.righttop, legendorientation = legendorientation.vertical };              // add axes, note minimumpadding , absoluteminimum should set on 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 series, note barseries using same itemssource 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; }     } } 

i'm not sure know trying do, hope helps you:

i took sample , played little bit around code , sample. think problem code have bind in categoryaxis, data not added bind directly in columnseries. using code, left first part is, , instead of columnseries bar = new columnseries() did:

        columnseries bar = new columnseries         {             fillcolor = oxyplot.oxycolors.yellow,             valuefield = "value1",             title = "value1",             itemssource = items         };         tmp.series.add(bar); 

this way data in items binded both in categoryaxis , in columnseries (of course if need more columns representing value2 , value3 values of items class can add new columnseries series of plotmodel)

then added button window, , in code-behind added:

        items.removeat(0);         model1.invalidateplot(true); 

and updates plot removing (each time) first columnseries including label in categoryaxis.

window code-behind:

using system.collections.objectmodel; using system.windows; using oxyplot; using oxyplot.axes; using oxyplot.series;  namespace oxyplot_test {     /// <summary>     /// interaction logic window2.xaml     /// </summary>     public partial class window2 : window     {         public window2()         {             initializecomponent();              // create 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 plot model             var tmp = new plotmodel { title = "column series", legendplacement = legendplacement.outside, legendposition = legendposition.righttop, legendorientation = legendorientation.vertical };              // add axes, note minimumpadding , absoluteminimum should set on value axis.             tmp.axes.add(new categoryaxis { itemssource = this.items, labelfield = "label" });             tmp.axes.add(new linearaxis { position = axisposition.left, minimumpadding = 0, absoluteminimum = 0 });              columnseries bar = new columnseries             {                 fillcolor = oxyplot.oxycolors.yellow,                 valuefield = "value1",                 title = "value1",                 itemssource = items             };             columnseries bar1 = new columnseries             {                 fillcolor = oxyplot.oxycolors.green,                 valuefield = "value1",                 title = "value1",                 itemssource = items             };             columnseries bar2 = new columnseries             {                 fillcolor = oxyplot.oxycolors.red,                 valuefield = "value1",                 title = "value1",                 itemssource = items             };             tmp.series.add(bar);             tmp.series.add(bar1);             tmp.series.add(bar2);              this.model1 = tmp;             this.datacontext = this;         }          public collection<item> items { get; set; }          public plotmodel model1 { get; set; }          private void button1_click(object sender, routedeventargs e)         {             items.removeat(0);             model1.invalidateplot(true);         }     }      public class item     {         public string label { get; set; }         public double value1 { get; set; }         public double value2 { get; set; }         public double value3 { get; set; }     } } 

<<--------------------------------- edit --------------------------------->>

if need 1 bar per category, need 1 value per item. can (as in previous example) remove or add items from/to collection (updating plot using invalidateplot. code-behind:

using system.collections.objectmodel; using system.windows; using oxyplot; using oxyplot.axes; using oxyplot.series;  namespace oxyplot_test {     /// <summary>     /// interaction logic window2.xaml     /// </summary>     public partial class window2 : window     {         public window2()         {             initializecomponent();              // create data             this.items = new collection<item>                             {                                 new item {label = "apples", value1 = 37},                                 new item {label = "pears", value1 = 7},                                 new item {label = "bananas", value1 = 23}                             };              // create plot model             var tmp = new plotmodel { title = "column series", legendplacement = legendplacement.outside, legendposition = legendposition.righttop, legendorientation = legendorientation.vertical };              // add axes, note minimumpadding , absoluteminimum should set on value axis.             tmp.axes.add(new categoryaxis { itemssource = this.items, labelfield = "label" });             tmp.axes.add(new linearaxis { position = axisposition.left, minimumpadding = 0, absoluteminimum = 0 });              columnseries bar = new columnseries             {                 fillcolor = oxyplot.oxycolors.black,                 valuefield = "value1",                 title = "value1",                 itemssource = items             };             tmp.series.add(bar);              this.model1 = tmp;             this.datacontext = this;         }          public collection<item> items { get; set; }          public plotmodel model1 { get; set; }          private void button1_click(object sender, routedeventargs e)         {             items.removeat(0);             model1.invalidateplot(true);         }          private void button2_click(object sender, routedeventargs e)         {             items.add(new item()             {                 label = "strawberrys", value1 = 55             });             model1.invalidateplot(true);         }     }      public class item     {         public string label { get; set; }         public double value1 { get; set; }     } } 

Comments