如何在Google图表行中提供一些自动的内容边距

时间:2019-05-09 19:27:53

标签: javascript charts google-visualization

我正在使用Google Charts绘制折线图,​​但我不明白如何在图形内容周围自动设置一些空格/边距。在documentation中,我发现最接近我想要的变量是viewWindowMode: 'pretty',但它不起作用。此外,即使我想在这里使用一些自动功能,我仍然希望通过告诉我想要多少利润来对其进行控制。

这是我现在得到的图形:

enter image description here

您可能会看到,图形的内容(线)触摸了hAxis,因为两个值在开始时都设置为11.900。最后,情况相同:最后一个数据位于图形顶部的12.400。我想在此留出一些余地,假设显示的vAxis从11.800到12.500。

当然,执行此操作的另一种方法是手动计算序列中最小和最大的序列号,然后手动告诉图形显示vAxis的值小于使用

的值
viewWindow: {
    min: minData
    ,max: maxData
}

这里的问题是,图中显示的内容不止一个(请注意上一张图片的顶部菜单),它们可能不相同。此时,第二个数据为纯0:

Second set of data

这是我当前的代码:

var options = {
    hAxis: {
        title: info.genericTitle
    },
    tooltip: {isHtml: true},
    vAxes: {
        // Adds titles to each axis.
        0: {title: var_title,
            viewWindowMode: 'pretty'
            //  ,baseline: 0
            /*,viewWindow: {
                min: minData
                ,max: maxData
            }*/
        },
        //https://developers.google.com/chart/interactive/docs/gallery/linechart
        1: {
            gridlines: {color: 'transparent', count: 2},
            baselineColor: 'transparent',
            textPosition: 'none'
            //,baseline: 0            
        }            
    },
    explorer: {
        actions: ['dragToZoom', 'rightClickToReset'],
        keepInBounds: true
    },

    seriesType: 'line',
    isStacked: false,

    chartArea: {
        backgroundColor: {
            gradient: {
                // Start color for gradient.
                color1: '#FFFFFF',
                // Finish color for gradient.
                color2: '#b3d9ff',
                //color2: '#1a82f7',
                // Where on the boundary to start and
                // end the color1/color2 gradient,
                // relative to the upper left corner
                // of the boundary.
                x1: '0%', y1: '0%',
                x2: '0%', y2: '100%'
            }
        },
        width: '80%'
    }
};

0 个答案:

没有答案