如何使用 OFC Python 绘制图表?

发布于 2024-11-26 19:39:30 字数 2224 浏览 4 评论 0原文

我需要可视化我的 trac 插件的数据。因此我想使用 Open Flash Charts 2。 尝试遵循这个并没有完全成功预期的。

问题

图表数据不会显示,唯一的输出是 OFC 的加载动画。 教程中的 html 源代码看起来也很相似。

如何将 JSON 数据加载到我的图表中?

其他信息

我编写了一个模板,应在其中输入处理后的数据。

CHART_TEMPLATE = Template(
              '''
              <script type=\"text/javascript\" src=\"$json_path/json2.js\">
              </script>
              <script type=\"text/javascript\" src=\"$js_path/swfobject.js\">
              </script>
              <script type=\"text/javascript\">
              swfobject.embedSWF(\"$ofc_path/open-flash-chart.swf\", 
\"$chartname\", \"$width\", \"$height\", \"9.0.0\");

              function open_flash_chart_data()
              {
              alert('reading data');
              return JSON.stringify($json_chart_data);
              }

              function ofc_ready()
              {
              alert('ofc_ready');
              }
              </script>

              <div id=\"$chartname\"></div>
              '''
              )

使用 Open Flash Charts python 将数据转换为 JSON,效果似乎很好。

def chartdata_from_timetable(self, dict, title):
    '''
    creates chartdata in JSON-format from 2 dim dictionary

    '''
    elements = []
    x_labels = []
    dc = DateConversion.DateConversion()
    # if startdate on a weekend, startdate might 
    not be inluced in the dict->    
    choose next monday
    for key in timetable[startdate]:
        element = Chart()
        element.type = "line"
        element.text = key
        values = []
        for date in dict:
            values.append(dict[date][key])
            x_labels.append(string_from_date(date))
        element.values = values
        elements.append(element)
    chart = Chart()
    chart.x_axis.labels = x_labels
    chart.title.text = title
    chart.elements = elements
    return chart.create().encode()

之后返回以下数据,似乎没有丢失:

CHART_TEMPLATE.safe_substitute(js_path = config['js_dir'],...,
json_chart_data = chart_data)

I need to visualize data for my trac Plugin. Therefore I want to use Open Flash Charts 2.
Trying to follow this didn't quite work out as expected.

Question

The Chartdata won't show, the only output is the loading-animation by OFC.
Everything looks similar too the html-source in the tutorial.

How can I load the JSON- Data into my chart?

Additional Information

I wrote a template where the processed data should be entered.

CHART_TEMPLATE = Template(
              '''
              <script type=\"text/javascript\" src=\"$json_path/json2.js\">
              </script>
              <script type=\"text/javascript\" src=\"$js_path/swfobject.js\">
              </script>
              <script type=\"text/javascript\">
              swfobject.embedSWF(\"$ofc_path/open-flash-chart.swf\", 
\"$chartname\", \"$width\", \"$height\", \"9.0.0\");

              function open_flash_chart_data()
              {
              alert('reading data');
              return JSON.stringify($json_chart_data);
              }

              function ofc_ready()
              {
              alert('ofc_ready');
              }
              </script>

              <div id=\"$chartname\"></div>
              '''
              )

The data is transformed to JSON with Open Flash Charts python, which seems to work well.

def chartdata_from_timetable(self, dict, title):
    '''
    creates chartdata in JSON-format from 2 dim dictionary

    '''
    elements = []
    x_labels = []
    dc = DateConversion.DateConversion()
    # if startdate on a weekend, startdate might 
    not be inluced in the dict->    
    choose next monday
    for key in timetable[startdate]:
        element = Chart()
        element.type = "line"
        element.text = key
        values = []
        for date in dict:
            values.append(dict[date][key])
            x_labels.append(string_from_date(date))
        element.values = values
        elements.append(element)
    chart = Chart()
    chart.x_axis.labels = x_labels
    chart.title.text = title
    chart.elements = elements
    return chart.create().encode()

Afterwards the following data is returned, none seems to be missing:

CHART_TEMPLATE.safe_substitute(js_path = config['js_dir'],...,
json_chart_data = chart_data)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送舟行 2024-12-03 19:39:30

您必须检查trac.iniofc文件夹的路径是否正确。
函数 chartdata_from_timetable 也不正确。由于覆盖,您只能看到最后一个条目的值。

You have to check if the path of the ofc folder in trac.ini is right.
The function chartdata_from_timetable is also not right. You only see the values of the last entry because of overwriting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文