lmt_chart_bar with data from luacode
![](https://secure.gravatar.com/avatar/8fb8e20562b276a1540891a8ce15c8f7.jpg?s=120&d=mm&r=g)
Dear Sirs If I tried: \starttext \startluacode sample = {10,30,30,40} function MP.GetP() mp.print(sample) end \stopluacode \startMPcode draw lmt_chart_bar [ width = 8cm, height = 10mm, samples = {lua.MP.GetP()} , trace = true, maximum = 100, linewidth = 1mm, showlabels = false, originsize = 0, labelanchor = "lft", labelcolor = "black" labelstyle = "bfxx" legendstyle = "tfxx", labelstrut = "yes", ] ; \stopMPcode \stoptext This works. But with an extra element in the sample table: \starttext \startluacode sample = {10,30,30,40,50} function MP.GetP() mp.print(sample) end \stopluacode \startMPcode draw lmt_chart_bar [ width = 8cm, height = 10mm, samples = {lua.MP.GetP()} , trace = true, maximum = 100, linewidth = 1mm, showlabels = false, originsize = 0, labelanchor = "lft", labelcolor = "black" labelstyle = "bfxx" legendstyle = "tfxx", labelstrut = "yes", ] ; \stopMPcode \stoptext Don't works anymore. Why? Thanks for your time and support. Sent with a Spark
![](https://secure.gravatar.com/avatar/46562c7d27388490d62e8d7a5bc960dd.jpg?s=120&d=mm&r=g)
On 7/23/2021 11:07 AM, Jorge Manuel wrote:
Dear Sirs
If I tried:
\starttext \startluacode sample = {10,30,30,40}
function MP.GetP() mp.print(sample) end \stopluacode
\startMPcode draw lmt_chart_bar [ width = 8cm, height = 10mm, samples = {lua.MP.GetP()} , trace = true, maximum = 100, linewidth = 1mm, showlabels = false, originsize = 0, labelanchor = "lft", labelcolor = "black" labelstyle = "bfxx" legendstyle = "tfxx", labelstrut = "yes", ] ; \stopMPcode
\stoptext
This works.
But with an extra element in the sample table:
\starttext \startluacode sample = {10,30,30,40,50}
function MP.GetP() mp.print(sample) end \stopluacode
\startMPcode draw lmt_chart_bar [ width = 8cm, height = 10mm, samples = {lua.MP.GetP()} , trace = true, maximum = 100, linewidth = 1mm, showlabels = false, originsize = 0, labelanchor = "lft", labelcolor = "black" labelstyle = "bfxx" legendstyle = "tfxx", labelstrut = "yes", ] ; \stopMPcode
\stoptext
Don't works anymore. Why? (watch out: samples is global in your code)
your lua.MP.GetP() becomes some mp quantity and 4 entries becomes a cmykcolor and you're just lucky that that works (reverse casting makes it a table) and there is no 5 element quantity so, you end up in scantokens not being able to understand it I'll think of a way to pass records (new submechanism) at some point but for now i added this: \startluacode document.samples = { { 10, 30, 30, 40, 50 } } \stopluacode \startMPcode draw lmt_chart_bar [ width = 8cm, height = 10mm, trace = true, maximum = 100, linewidth = 1mm, showlabels = false, sampleset = "document.samples", originsize = 0, labelanchor = "lft", labelcolor = "black" labelstyle = "bfxx" legendstyle = "tfxx", labelstrut = "yes", ] ; \stopMPcode with the spec being some lua, so this will also work: sampleset = "table.load('foo.lua')", asuming foo.lua has this: return { { 10, 30, 30, 40, 50 } } ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/8fb8e20562b276a1540891a8ce15c8f7.jpg?s=120&d=mm&r=g)
Dear Hans
I tried this code, but it didn't work. This is not my day.
%%%%%%%%%%%%%%%
\starttext
\startluacode
document.samples = {
{ 10, 30, 30, 40, 50 }
}
function document.dados()
return { { 10, 30, 30, 40, 50 }}
end
\stopluacode
\startMPcode
draw lmt_chart_bar [
samples = "table.load('document.dados')",
percentage = true,
cumulative = true,
showlabels = false,
backgroundcolor = "lightgray",
] ;
\stopMPcode
\startMPcode
draw lmt_chart_bar [
width = 8cm,
height = 10mm,
trace = true,
maximum = 100,
linewidth = 1mm,
showlabels = false,
samples = "document.samples",
originsize = 0,
labelanchor = "lft",
labelcolor = "black"
labelstyle = "bfxx"
legendstyle = "tfxx",
labelstrut = "yes",
] ;
\stopMPcode
\stoptext
%%%%%%%%%%%%%%%%%%%%%
Jorge Magalhães
On 23 Jul 2021, 16:58 +0100, Hans Hagen
\startMPcode
draw lmt_chart_bar [ width = 8cm, height = 10mm, trace = true, maximum = 100, linewidth = 1mm, showlabels = false, sampleset = "document.samples", originsize = 0, labelanchor = "lft", labelcolor = "black" labelstyle = "bfxx" legendstyle = "tfxx", labelstrut = "yes", ] ; \stopMPcode
participants (3)
-
Floris van Manen
-
Hans Hagen
-
Jorge Manuel