简体   繁体   English

无法使用Google图表创建完整的饼图

[英]unable to Create Complete Pie Chart using Google Charts

i have been trying to implement the google Graph and Dashboard, 我一直在尝试实现Google Graph和Dashboard,

Here is the snippet for my code, 这是我的代码的片段,

     <script type="text/javascript">

            function drawVisualization(dataArray) {
                //                function drawVisualization() {
                // Prepare the data
                var data = google.visualization.arrayToDataTable(dataArray);
                // Define a category picker control for the Gender column
                var categoryPicker = new google.visualization.ControlWrapper({
                    'controlType': 'CategoryFilter',
                    'containerId': 'control2',
                    'options': {
                        'filterColumnLabel': 'Provider State',
                        'ui': {
                            'labelStacking': 'vertical',
                            'allowTyping': false,
                            'allowMultiple': false
                        }
                    }
                });

                // Define a Pie chart
                var pie = new google.visualization.ChartWrapper({
                    'chartType': 'PieChart',
                    'containerId': 'chart1',
                    'options': {
                        'width': 300,
                        'height': 300,
                        'legend': 'none',
                        'title': 'Demo Data Displayed',
                        'chartArea': {'left': 15, 'top': 15, 'right': 0, 'bottom': 0},
                        'pieSliceText': 'label'
                    },
                    // Instruct the piechart to use colums 0 (Name) and 3 (Donuts Eaten)
                    // from the 'data' DataTable.
                    'view': {'columns': [1, 5]}
                });

                // Define a table
                var table = new google.visualization.ChartWrapper({
                    'chartType': 'Table',
                    'containerId': 'chart2',
                    'options': {
                        'width': '300px'
                    }
                });

                // Create a dashboard
                new google.visualization.Dashboard(document.getElementById('dashboard')).
                    // Establish bindings, declaring the both the slider and the category
                // picker will drive both charts.
                bind([categoryPicker], [pie, table]).
                    //                    bind([pie, table]).
                // Draw the entire dashboard.
                draw(data);
            }

        </script>
// This is the dataArray [["DRG Definition","Provider State","Total Discharges","Average Covered Charges","Average Total Payments","id"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","AL","879","29855.3481218009","5857.17519906485","2"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","AZ","606","33581.3151824257","7034.48184806271","4"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","CO","255","33554.1607857647","6911.51372542745","6"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","DC","47","44919.3829785106","9241.59574459574","8"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","FL","2847","38464.4531085423","6145.54970143098","10"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","HI","24","27809.95833","10982.04167","12"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","ID","113","18150.97345","6457.23893819469","14"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","IN","1078","26888.4359918275","6597.5454545872","16"],["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","KY","728","22308.0645596154","6347.6085165467","18"],....

The Problem here is that my graph(pie chart) do generate but it loads only partially lets say if i select 1 value from category drop down,only its pie is displayed, i cannot see other values from the chart, i hope some 1 can help me here. 这里的问题是我的图形(饼图)确实生成,但是它只能部分加载,如果我从类别下拉列表中选择1个值,则仅显示其饼图,我无法从图表中看到其他值,希望有1个可以在这帮我

First off, as I mentioned in my answer to your other question , you have to input your numbers as numbers, not strings, if you want the PieChart to work. 首先,正如我在对另一个问题的回答中提到的那样,如果要使用PieChart,则必须将数字输入为数字,而不是字符串。 As an example, you need to change this: 例如,您需要更改此设置:

["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","AL","879","29855.3481218009","5857.17519906485","2"]

to this: 对此:

["039 - EXTRACRANIAL PROCEDURES W\/O CC\/MCC","AL",879,29855.3481218009,5857.17519906485,2]

With that fixed, the control works exactly as you designed it: it filters on the "Provider State" column. 修复此问题后,控件将完全按照您的设计工作:它在“提供者状态”列上进行过滤。 With the sample data you provided, the PieChart only shows one slice, but that is because the data only contains one row per state. 使用您提供的示例数据,PieChart仅显示一个切片,但这是因为每个状态数据仅包含一行。 See working example based on your code here: http://jsfiddle.net/asgallant/tqB92/ 在此处查看基于您的代码的工作示例: http : //jsfiddle.net/asgallant/tqB92/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM