【问题标题】:Google Charts ColumnChart hard min axis value overflows label (Chrome only)Google Charts ColumnChart 硬最小值轴值溢出标签(仅限 Chrome)
【发布时间】:2015-01-10 00:06:24
【问题描述】:

我正在从 Google Charts API 构建一个堆叠的 ColumnChart,一切都很好 - 大多数情况下。它是带有双 y 轴的股票信息。

仅在 chrome 中,当我将 viewWindow 最小值设置为大于 0 以调整图表时,列不会停在图表的底部垂直边界,而是渗入标签.

图表在这里: http://ir.stockpr.com/mainstcapital/stock-information

铬:

图表数据全部正确。

代码:

function drawVisualization() {

  var data = google.visualization.arrayToDataTable([
    <?= $chart_data ?>
  ]);

  var options = {
      legend: { position: 'top', textStyle: {color: '#333', fontSize: 10, fontName: 'Arial', bold: false, italic: false} },
      isStacked: true,
      title : 'Historical Dividend, Distributable Net Investment Income (“DNII”), And Net Asset Value (“NAV”) Per Share Growth',
      vAxes: {
        0: {title: "DNII and Dividends Per Share", viewWindowMode: 'explicit', viewWindow: { min: 0.2, max: 1 } }, 
        1: {title: "NAV Per Share", viewWindowMode: 'explicit', viewWindow: { min: 8, max: 24 } }
     },

    hAxis: {title: "As of <?= $last_day_of_last_complete_quarter ?>, <?= $last_complete_year ?>"},

    series: {
        0: {type: "bars", color: '#6d6d66', targetAxisIndex: 0},
        1: {type: "bars", color: '#d4d4d4', targetAxisIndex: 0},

        2: {type: "line", color: 'green', lineWidth: 3, targetAxisIndex: 1},
        3: {type: "line", color: 'red', lineWidth: 3, targetAxisIndex: 0},
    }   

  };

  var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
  chart.draw(data, options);
}

我可以做一些 CSS 来解决这个问题吗?我什么都想不通。还是我在 API 中遗漏了什么?任何帮助表示赞赏,在此先感谢您。

【问题讨论】:

    标签: javascript css google-chrome charts google-visualization


    【解决方案1】:

    由于 url 不正确,未应用 google.visualization 生成的 svg 的剪辑路径。这是由 head 部分中的基本标记引起的:

    <base href="http://mainstcapital.sites.equisolve.com">
    

    2 种可能的解决方案:

    1。 移除基础标签

    2。 在此处添加以下功能:https://code.google.com/p/google-visualization-api-issues/issues/detail?id=598

    但它不太可能永远有效:)

    function fixGoogleCharts(){
    
    $( 'svg', "#chart_div" ).each( function() {
        $( this ).find( "g" ).each( function() {
            if ($( this ).attr( 'clip-path' )){
                if ( $( this ).attr( 'clip-path' ).indexOf( 'url(#') == -1) return;
                $( this ).attr( 'clip-path', 'url(' + document.location + $( this ).attr( 'clip-path' ).substring( 4 ) )
            }
        });
        $( this ).find( "rect" ).each( function() {
            if($( this ).attr( 'fill' )){
                if ( $( this ).attr( 'fill' ).indexOf( 'url(#') == -1) return;
                $( this ).attr( 'fill', 'url(' + document.location + $( this ).attr( 'fill' ).substring( 4 ) )
            }
        });
    }); }
    

    并大声喊叫

    chart.draw(data, options);
    

    添加

    google.visualization.events.addListener( chart, 'ready', fixGoogleCharts() );
    

    希望对你有帮助

    【讨论】:

    • 我更喜欢删除基本标签,但我们目前的设置不能。第二种选择,虽然它可能是暂时的,但就像一个魅力。非常感谢!
    猜你喜欢
    • 2011-09-15
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    相关资源
    最近更新 更多