c# - Change color of LineSeries -
hoping can help. i've spent 4hrs far trying examples i've found on forums no avail. below xaml code; think there a simple way insert parameter set color, i've not found 1 works.
i've tried code behind; examples i've found not change anything.
<grid> <charting:chart name="linechart" title="stock" verticalalignment="top" margin="0,10,10,0" height="550"> <charting:lineseries name="price" title="price" dependentvaluepath="value" independentvaluepath="key" itemssource="{binding [0]}" isselectionenabled="true"/> <charting:lineseries name="sma50" title="50 sma" dependentvaluepath="value" independentvaluepath="key" itemssource="{binding [1]}" isselectionenabled="true"/> <charting:lineseries name="sma200" title="200 sma" dependentvaluepath="value" independentvaluepath="key" itemssource="{binding [2]}" isselectionenabled="true"/> </charting:chart> </grid>
here code calls window
private void bgraph_click(object sender, routedeventargs e) { graph g = new graph(); g.show(); list<keyvaluepair<datetime, int>> listprice = new list<keyvaluepair<datetime, int>>(); list<keyvaluepair<datetime, int>> listsma50 = new list<keyvaluepair<datetime, int>>(); list<keyvaluepair<datetime, int>> listsma200 = new list<keyvaluepair<datetime, int>>(); datetime d = new datetime(2000,1,1); (int = 1; < 10; i++) { listprice.add(new keyvaluepair<datetime, int>(d, i)); listsma50.add(new keyvaluepair<datetime, int>(d, i*2)); listsma200.add(new keyvaluepair<datetime, int>(d, * 3)); d = d.adddays(1.0); } var datasourcelist = new list<list<keyvaluepair<datetime, int>>>(); datasourcelist.add(listprice); datasourcelist.add(listsma50); datasourcelist.add(listsma200); g.linechart.datacontext = datasourcelist; }
any awesome. appears me windows form version of charting lot simpler use wpf version.
you specify datapointstyle property:
<charting:lineseries name="price" title="price" dependentvaluepath="value" independentvaluepath="key" itemssource="{binding [0]}" isselectionenabled="true" datapointstyle="{staticresource mydatapointstyle}" />
which in case i'm assuming static resource:
<style x:key="mydatapointstyle" targettype="{x:type charting:linedatapoint}"> <setter property="background" value="blue"/> </style>
if need dynamically , don't want use data binding can of course programatically:
var style = new style(); style.targettype = typeof(linedatapoint); style.setters.add(new setter(backgroundproperty, brushes.blue)); this.price.datapointstyle = style;
Comments
Post a Comment