【问题标题】:Dynamic google charts configuration动态谷歌图表配置
【发布时间】:2016-12-02 03:51:39
【问题描述】:

我们计划在我们的项目中使用谷歌图表,并且我们使用 Angular JS 作为前端。 (Angular 和 Google 图表的新功能)

Google 图表是否提供任何现成的用户界面来配置每种类型的图表?

如果用户选择图表类型,它应该向用户显示配置,一旦用户选择,它将应用于该图表。

例如:

  1. 如果选择饼图,将显示“pieHole”字段。

  2. 如果选择条形图,将显示“isStacked”字段。

提前致谢:)

【问题讨论】:

    标签: javascript angularjs charts google-visualization pygooglechart


    【解决方案1】:

    查看ChartEditor Class

    下面的工作 sn-p 打开一个带有填充饼图的图表编辑器对话框

    当图表编辑器打开时,查看自定义标签以了解各种图表选项

    点击“确定”将图表保存到页面上的<div>

    google.charts.load('current', {
      callback: function () {
        var chartEditor = null;
    
        // Create the chart to edit
        var chartWrapper = new google.visualization.ChartWrapper({
          chartType: 'PieChart',
          dataTable: new google.visualization.DataTable({
            "cols": [
              {"label": "Country", "type": "string"},
              {"label": "# of Devices", "type": "number"}
            ],
            "rows": [
              {"c": [{"v": "Canada"}, {"v": 33}]},
              {"c": [{"v": "Mexico"}, {"v": 33}]},
              {"c": [{"v": "USA"}, {"v": 34}]}
            ]
          })
        });
        chartEditor = new google.visualization.ChartEditor();
        google.visualization.events.addListener(chartEditor, 'ok', redrawChart);
        chartEditor.openDialog(chartWrapper, {});
    
        // On "OK" save the chart to a <div> on the page.
        function redrawChart(){
          chartEditor.getChartWrapper().draw(document.getElementById('chart_div'));
        }
      },
      packages:['charteditor', 'controls']
    });
    <script src="https://www.gstatic.com/charts/loader.js"></script>
    <div id="chart_div"></div>

    【讨论】:

    • 太棒了 :) 非常感谢.. 将研究该课程 :)
    • 还有一个问题。我们是否只需要从该调色板中的 80 种颜色中进行选择?如果用户必须使用 RGB 数字或 Hex 数字来选择颜色,我们需要做什么??
    • 您可以将自己的颜色提供给图表的colors 选项,或者使用其他方式之一来提供颜色,例如'style' 列——对于RGB,这些是目前不支持 -- 但是,可以在绘制图表后手动更改图表颜色 -- here is a working example 使用 rgba(...)
    • 我想保存一次图表配置并在不同时间获取数据,然后使用保存的配置和数据绘制图表。为此,我想使用 chartEditor 类。因此,如果用户想要选择颜色,应该可以灵活地在 chartEditor 中选择任何颜色。我想知道如何向 chartEditor 调色板添加更多颜色。请帮忙
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多