简体   繁体   English

如何自定义Google图表中特定点的颜色

[英]How to customize color of specific point in Google charts

How to customize color of specific date point on data chart from Google analytics embedded API . 如何通过Google Analytics(分析)嵌入式API自定义数据图表上特定日期点的颜色。 After I read Google Visualization API documentation I tried this code but it didn't work: 阅读Google Visualization API文档后,我尝试了以下代码,但没有成功:

var sessionsOverMonth = new gapi.analytics.googleCharts.DataChart({
        reportType: 'ga',
        query: {
            'dimensions': 'ga:date',
            'metrics': 'ga:sessions',
            'start-date': '30daysAgo',
            'end-date': 'yesterday',
        },
        chart: {
            type: 'LINE',
            container: 'sessions-over-month',
            options: {width: '100%' ,
                series: {
                    0: { pointShape: { type: 'star', sides: 5, dent: 0.05 }},
                }
            }
        }
    });

how to catch specific date on chart and customize it ? 如何在图表上捕获特定日期并对其进行自定义?

settings within the series option, will affect the entire data series, or column of data series选项中的设置会影响整个数据系列或数据列

to change a specific point within a series, requires using a column role , 要更改系列中的特定点,需要使用列角色
specifically --> style 专门-> 风格

the following working snippet shows how in the google-visualization library 以下工作片段显示了如何在google-visualization库中

 google.charts.load('current', { callback: drawChart, packages: ['corechart'] }); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Date', 'y', {role: 'style'}], [new Date(2017, 2, 1), 0, null], [new Date(2017, 2, 2), 1, null], [new Date(2017, 2, 3), 2, 'point {size: 16; shape-type: star; fill-color: #d81b60;}'], [new Date(2017, 2, 4), 3, null], [new Date(2017, 2, 5), 4, null], [new Date(2017, 2, 6), 5, null] ]); var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, { pointSize: 6 }); } 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div> 

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

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