我如何使用 MediaWiki 中的 Lua 模块来显示图表

How can I use a Lua module in MediaWiki to display graphs

我目前有一个 Lua 模块,可以对传递的数据进行一些操作,然后我希望它能在文章中显示图表。

我无法正确显示图表,但到目前为止我已经尝试了几种方法:

Output in the form of {{Graph:Chart|variablesHere}} using the graph template as is recommended on the extension page, which works fine usually. The problem with this approach is that (I assume) because it comes from a module the text isn't actually processed by MediaWiki and therefore display plaintext.

Using require('Module:Graph') and and printing the output to the page, however it does not correctly make a graph either as it isn't properly formatted and I haven't been able to understand how to convert it like Template:Graph:Chart does

只是在寻找关于从这里去哪里的任何建议。

使用 frame:preprocess(string_containing_templates) 扩展包含 Template:Graph:Chart.

等模板的字符串

如果你想避免预处理,你可以调用Module:Graphchart函数,但是得到与扩展Template:Graph:Chart相同的结果是复杂的,因为你必须翻译Template:Chart:Graph 到 Lua 的内容。要生成与 frame:preprocess("{{Graph:Chart|width=100|height=100|x=1|y=1}}") 相同的内容,您可以这样做:

 frame:extensionTag("templatestyles", nil, { src = "Graph:Chart/styles.css" })
  .. frame:extensionTag (
    "graph",
    require("Module:Graph").chart { args = { width = '100', height = '100', x = '1', y = '1' } }
  )

这里frame必须是框架对象。不是很漂亮,如果对模板进行任何更改,它们将不会反映在您的模块代码中。所以最好只预处理模板。