Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Suppose I am provided with two data lists. (Assume for the moment that they are lists of integers.) I would like a function that generates bar charts that I can manipulate.

Here is what I have:

f[dL1_List, dL2_List] :=
  Module[{dL1SymList, dL2SymList},
   dL1SymList = (Symbol["dL1" <> ToString[#]] &) /@ dL1;
   dL2SymList = (Symbol["dL2" <> ToString[#]] &) /@ dL2;
   (
     Manipulate[Grid[{
         {
          BarChart[dL1SymList, PlotLabel -> "dL1"],
          BarChart[dL2SymList, PlotLabel -> "dL2"]
          }
         }], ##] &
     ) @@
    Join[
     MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL1SymList, dL1}],
     MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL2SymList, dL2}]
     ]
   ];

f[Range[1, 5], Range[1, 5]]

However, while this does not produce any error, it does not display bar graphs either. Can you please help me understand where I am going wrong?

Thanks in advance for your help.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Just to get it working: you need to read and fully grok the documentation for Manipulate... it explains in detail why constructs like this are used, and the changes in "expected" behaviors within Manipulate.

f[dL1_List, dL2_List] := 
  Module[{dL1SymList, dL2SymList}, 
   dL1SymList = (Symbol["dL1" <> ToString[#]] &) /@ dL1;
   dL2SymList = (Symbol["dL2" <> ToString[#]] &) /@ dL2;
   (With[{dL1SymList = dL1SymList, dL2SymList = dL2SymList}, 
       Manipulate[
        Grid[{{BarChart[dL1SymList, PlotLabel -> "dL1"], 
           BarChart[dL2SymList, PlotLabel -> "dL2"]}}], ##]] &) @@ 
    Join[MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL1SymList, dL1}], 
     MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL2SymList, dL2}]]];

f[Range[1, 3], Range[1, 2]]

enter image description here

share|improve this answer
    
Thank you very much indeed! –  Shredderroy Apr 3 at 5:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.