2017-03-07 55 views
2

如何自定义Google analytics embedded API的数据图表上特定日期点的颜色。 后,我看了Google Visualization API documentation我想这个代码,但没有奏效:如何自定义Google图表中特定点的颜色

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 }}, 
       } 
      } 
     } 
    }); 

如何捉对图表特定日期和自定义它?在series选项内

回答

0

设置,会影响数据

的整个数据序列,或列于一系列内变化的特定点,需要使用column role
具体 - >风格

以下工作片段展示了如何在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>

+0

我不确定'google-analytics',数据集中是否有一列可用作_style_列? – WhiteHat

+0

是WhiteHat,您的代码正在处理可视化,但在状态Google Analytics(分析)中,除宽度属性外,没有图表的样式属性。 –