谷歌条形图(有过滤器)每列的栏中有不同的颜色

时间:2013-03-21 10:08:02

标签: jquery bar-chart google-visualization google-chartwrapper

以下是我的google-chart javascript

<script type="text/javascript">
    google.load('visualization', '1.1', {packages: ['controls']});
</script>

<script type="text/javascript">
    function drawVisualization() {
        // Prepare the data
        var data = google.visualization.arrayToDataTable([
                 ['Country', 'Position', 'Prosthethis type', 'Units'],
                 ['Europe', 'Aortic',  'Mechanical',  5007],
                 ['Europe', 'Aortic',  'Biological',  15434],
                 ['Europe', 'Mitral',  'Mechanical',  1974],
                 ['Europe', 'Mitral',  'Biological',  3550],
                 ['France', 'Aortic',  'Mechanical',  803],
                 ['France', 'Aortic',  'Biological',  2277],
                 ['France', 'Mitral',  'Mechanical',  229],
                 ['France', 'Mitral',  'Biological',  436]
               ]);

        var countryPicker = new google.visualization.ControlWrapper({
                                'controlType': 'CategoryFilter',
                                'containerId': 'control4',
                                'options': {
                                    'filterColumnLabel': 'Country',
                                    'ui': {
                                        'labelStacking': 'vertical',
                                        'allowTyping': false,
                                        'allowMultiple': false
                                    }
                                },
                                'state': {'selectedValues': ['Europe']}
                            });

        var regionPicker = new google.visualization.ControlWrapper({
                                'controlType': 'CategoryFilter',
                                'containerId': 'control5',
                                'options': {
                                    'filterColumnLabel': 'Position',
                                    'ui': {
                                        'labelStacking': 'vertical',
                                        'allowTyping': false,
                                        'allowMultiple': false
                                    }
                                }
                            });

        var cityPicker = new google.visualization.ControlWrapper({
                                'controlType': 'CategoryFilter',
                                'containerId': 'control6',
                                'options': {
                                    'filterColumnLabel': 'Prosthethis type',
                                    'ui': {
                                        'labelStacking': 'vertical',
                                        'allowTyping': false,
                                        'allowMultiple': false
                                    },
                                }
                            });

        var barChart = new google.visualization.ChartWrapper({
                                'chartType': 'BarChart',
                                'containerId': 'chart3',
                                'options': {
                                    'width': 400,
                                    'height': 300,
                                    'chartArea': {top: 0, right: 0, bottom: 0}
                                },
                                // Configure the barchart to use columns 2 (City) and 3 (Population)
                                'view': {'columns': [2, 3]}


                            });

                            new google.visualization.Dashboard(document.getElementById('visualization2')).
                                // Configure the controls so that:
                            // - the 'Country' selection drives the 'Region' one,
                            // - the 'Region' selection drives the 'City' one,
                            // - and finally the 'City' output drives the chart
                            bind(countryPicker, regionPicker).
                                bind(regionPicker, cityPicker).
                                bind(cityPicker, barChart).
                                // Draw the dashboard
                            draw(data);
    }

    google.setOnLoadCallback(drawVisualization);
</script>

这是我的Html页面....

 <html>
    <head>
        <title>Untitled Document</title>
        <script type="text/javascript" src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load('visualization', '1', {packages: ['corechart']});
        </script>
    </head>
    <body>               
        <table width="100%" border="1" cellspacing="0" cellpadding="5" bordercolor="#333333">
            <tr>
                <td bgcolor="#333333" class="heading-text">TEST</td>
            </tr>
            <tr>
                <td bgcolor="#FFFFFF" class="text" align="center" id="visualization2"><br/><br/>
                    <table>
                        <tr style='vertical-align: top'>
                            <td style='width: 300px; font-size: 0.9em;'>
                                <div id="control4"></div>
                                <div id="control5"></div>
                                <div id="control6"></div>
                            </td>
                            <td style='width: 600px'>
                                <div style="float: left;" id="chart3"></div>
                                <div style="float: left;" id="chart4"></div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </td>
    </tr>
</table>
</body>
</html>*

我想在这张图中只做一件事:我想要RED中的'Biological'列和蓝色中的'Mechanical'。

目前所有列均为蓝色。

我找到了许多不同颜色列的网站.....但它们对我不起作用。

请帮帮我。

...谢谢

1 个答案:

答案 0 :(得分:2)

这是一个解决方案。您需要添加

series: [{color: 'blue', visibleInLegend: true}, 
           {color: 'red', visibleInLegend:false}]

在您的选项中。

这也不是确切的解决方案。这是一种解决方法,您可以添加重复列并为所有其他数据隐藏该列,但您需要不同颜色的数据。

以下是工作sample.有关谷歌图表的更多相关查询,请查看此内容。 jqfaq.com