html - 使用 High Charts 和 Bootstrap 3 的响应式折线图

标签 html css twitter-bootstrap-3 highcharts

目前我的 HighChart 折线图如下:

<script language="javascript" type="text/javascript">

    var highColors = [bgSystem, bgSuccess, bgWarning, bgPrimary];

    // Chart data
    var seriesData = [{
        name: 'Total Accounts',
        data: [5, 9, 12, 15, 17, 22, 28, 30, 34, 36, 38, 46]
    }, {
        name: 'Total Songs',
        data: [2, 3, 4, 5, 8, 12, 17, 23, 30, 34, 44]
    }, {
        name: 'Total Recordings',
        data: [15, 19, 22, 29, 32, 34, 36, 40, 42, 44, 45]
    }, {
        name: 'Total Writers',
        data: [11, 13, 15, 18, 24, 28, 30, 34, 38, 40, 42, 45]
    }];

    var dashboardChart = $('#dashboard_chart');
    if (dashboardChart.length) {
        dashboardChart.highcharts({
            credits: false,
            colors: highColors,
            chart: {
                backgroundColor: 'white',
                className: '',
                type: 'line',
                zoomType: 'x',
                panning: true,
                panKey: 'shift',
                marginTop: 45,
                marginRight: 1,
            },
            title: {
                text: null
            },
            xAxis: {
                gridLineColor: '#EEE',
                lineColor: '#EEE',
                tickColor: '#EEE',
                categories: ['Jan', 'Feb', 'Mar', 'Apr',
                    'May', 'Jun', 'Jul', 'Aug',
                    'Sep', 'Oct', 'Nov', 'Dec'
                ]
            },
            yAxis: {
                min: 0,
                tickInterval: 5,
                gridLineColor: '#EEE',
                title: {
                    text: 'Total'
                }
            },
            plotOptions: {
                spline: {
                    lineWidth: 3,
                },
                area: {
                    fillOpacity: 0.2
                }
            },
            exporting: {
                enabled: false
            },
            legend: {
                enabled: true,
                floating: false,
                align: 'right',
                verticalAlign: 'top',
                x: -5
            },
            series: seriesData
        });
    }
</script>

这是它在我的 HTML 中的显示方式

<div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div id="dashboard_chart" style="height: 500px; width:100%;"></div>
    </div>
</div>

主要问题是图形不适合平板电脑的整个容器(纵向和横向)。有没有人有什么建议?至于如何在不添加内联样式的情况下使其具有响应性?

最佳答案

您可以在高级图表初始化中设置响应式图表的选项。它允许您指定不同的宽度和高度,并且您可以指定不同的值,例如隐藏标签或显示某些内容。

dashboardChart.highcharts({
 options:values,
 options:values,
 ....
 ....
 responsive: {
    rules: [{
        condition: {
            maxWidth: 500
        },
        chartOptions: {
            legend: {
                align: 'center',
                verticalAlign: 'bottom',
                layout: 'horizontal'
            },
            yAxis: {
                labels: {
                    align: 'left',
                    x: 0,
                    y: -5
                },
                title: {
                    text: null
                }
            },
            subtitle: {
                text: null
            },
            credits: {
                enabled: false
            }
        }
    }]
}

})

这是他们官方文档的链接:https://www.highcharts.com/demo/responsive

关于html - 使用 High Charts 和 Bootstrap 3 的响应式折线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51855166/

相关文章:

html - 如何使模态框在其父div之外打开

html - 在 ul 和 li 标签之间添加空格 css inline

javascript - HTML DOM - 新元素采用错误的值?

html - CSS:防止 Unicode 字符的 'font-size' 增加其父容器维度

javascript - 使用 HTML/JS/CSS 缩短链接

html - 如何修复我的列表,这样我就不必在图标更新前切换两次?

html - Bootstrap 4 col-sm-6 inside col-sm-6 不工作

java - 使用 iText 将 HTML 转换为 PDF 时出错

html - 列在 768px 处折叠,菜单在 767px 处折叠?

javascript - 如何在 SVG 中创建嵌入阴影(透明背景)?