wpf - C# linechart dynamicly databind -


so want able create charts dynamicly created following class method called getchart()

    using system; using system.collections.generic; using system.linq; using system.text; using system.windows.controls.datavisualization.charting; namespace henvendelser {     class chartdatacreator     {         private dictionary<string, list<contactqueue>> datalist;          public chartdatacreator() {          }          public chart getchart(string choice) {              chart c = new chart();             lineseries ls = new lineseries();             ls.independentvaluebinding="{binding path=key}";             ls.dependentvaluebinding="{binding path=value}";             ls.itemssource =              new keyvaluepair<int, int>[]{             new keyvaluepair<int,int>(1, 12),             new keyvaluepair<int,int>(2, 25),             new keyvaluepair<int,int>(3, 5),             new keyvaluepair<int,int>(4, 6),             new keyvaluepair<int,int>(5, 10),             new keyvaluepair<int,int>(6, 4),             new keyvaluepair<int,int>(7, 40),             new keyvaluepair<int,int>(8, 12),             new keyvaluepair<int,int>(9, 25),             new keyvaluepair<int,int>(10, 5),             new keyvaluepair<int,int>(11, 6),             new keyvaluepair<int,int>(12, 10),             new keyvaluepair<int,int>(13, 4),             new keyvaluepair<int,int>(14, 8),             new keyvaluepair<int,int>(15, 9),             new keyvaluepair<int,int>(16, 50),             new keyvaluepair<int,int>(17, 40) };             c.series.add(ls);             return c;         }     } } 

now can see code has error the:

ls.independentvaluebinding="{binding path=key}"; ls.dependentvaluebinding="{binding path=value}";

my question how set independent , dependent binding dynamicly. please point out if there else im missing in order make work.

try this, looking binding objects thats have provide it.

chart c = new chart(); lineseries ls = new lineseries(); // new binding provide string path property. binding bindind = new binding("key"); binding binddep = new binding("value"); // can set properties of binding bindind.source = <your source>; binddep.source = <your source>; binddep.mode = bindingmode.oneway; bindind.mode = bindingmode.oneway; ls.independentvaluebinding = bindind; ls.dependentvaluebinding =binddep; 

Comments