In the following minimal working example:
Manipulate[BarChart[{a,b}],{a,1,2},{b,1,2}]
I'd like to be able to control the size of the bars by using some sort of Locator
property for manipulate i.e. change the vertical size of each bar by placing my mouse on the edge of the bar (ideally anywhere along its width).
Obviously, Locator
won't work. Any ideas how to easily do this?
I want the value of the bar chart to dynamically update. In the above example, I would have a, b
obey some constraint (like a + b = 2
so whenever one changes the other does so accordingly).
-------- Answered --------
This was so that there's some playing with the Greek general election. I wanted to play with the latest poll results and vary them before the election on Sunday.
@Mike Honeychurch: You are right, barspacing doesn't change the locator positioning but the locators are off center like so (this is my output when I run your code):
I assume you run a different version of Mathematica than me - I run 7, sorry, should have said so. So, I had to fiddle with the x-coordinates of your locators in some way like this when defining pt
:
numberofpoints = 5;
barspacing = 0.1;
xcoords = Table[i + barspacing i - 1/2, {i, 1, numberofpoints}];
pt = xcoords~Riffle~RandomInteger[{0, 3}, 3]~Partition~2
I got the chart to look OK at the end (locators here for only the first three bars):
but wasn't entirely happy with the way it was done because of the fiddling I mentioned above. So I am going with @Heike 's approach that works a treat out of the box exactly the way I wanted:
lastpoll = {{LightBlue, 24.3, "ΝΔ"}, {Green, 15.4, "ΠΑΣΟΚ"}, {Red, 10.9, "ΚΚΕ"},
{Yellow, 8, "ΔΗΜΑΡ"}, { Pink, 9.5, "ΣΥΡΙΖΑ"}, {Blue, 9.6, "Αν. Ελληνες"},
{Gray, 6.3, "Χρυση Αυγη"}, {LightBlue, 4.2, "ΛΑΟΣ"}, {Green, 4.4, "Οικολογοι"},
{LightCyan, 2.1, "Δημ. Συμμαχια"}, {Yellow, .8, "ΕΠΑΜ"}, { LightRed, .8, "ΔΡΑΣΗ"},
{Blue, .8, "ΑΝΤΑΡΣΥΑ"}, {LightGray, .8, "Κοιν. Συμφωνια"}, {White, 2, "Λοιπα"}};
values = #[[2]] & /@ lastpoll;
dragBar[values,
ChartLabels -> Placed[(Last /@ lastpoll), Axis, Rotate[#, 55 Degree] &],
ChartStyle -> (First /@ lastpoll), BarSpacing -> .6, ImageSize -> Large]
with the following result (all fiddlable):
In any case, thank you all for taking the time. This was harder than I expected it would be..