如何在Bootstrap行中对齐动态加载的Highcharts?

huangapple go评论81阅读模式
英文:

How to align dynamic loaded high charts in bootstrap row

问题

I want to show charts in bootstrap row. Just 3 in one line as shown in image.
Please help me to align these dynamic charts.

我想在Bootstrap行中显示图表,就像图像中显示的那样,一行中只有3个图表。请帮助我对齐这些动态图表。

英文:

I'm using HighCharts for chart display.
I'm using chart type solidgauge .
I'm loading dynamic charts, and I want to align these charts horizontally.

Basically, I want to align charts as shown in the image below.
如何在Bootstrap行中对齐动态加载的Highcharts?

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

function getChartOptions(data) {
        debugger;
        var rawData = data;
        var chartData = getData(rawData);

        function getData(rawData) {
            var data = [],
                start = Math.round(Math.floor(rawData / 10) * 10);
            data.push(rawData);
            for (i = start; i &gt; 0; i -= 10) {
                data.push({
                    y: i
                });
            }
            return data;
        }
        var options = {
            chart: {
                type: &#39;solidgauge&#39;,
                height: 250
            },
            credits: {
                enabled: false
            },
            title: {
                //
            },
            tooltip: {
                enabled: false
                /*valueSuffix: &#39; km/h&#39;*/
            },
            pane: {
                startAngle: -120,
                endAngle: 120,
                background: [{ // Track for Move
                    outerRadius: &#39;100%&#39;,
                    innerRadius: &#39;80%&#39;,
                    backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.3).get(),
                    borderWidth: 0,
                    shape: &#39;arc&#39;
                }],
            },
            yAxis: {
                min: 0,
                max: 100,
                lineWidth: 2,
                lineColor: &#39;white&#39;,
                tickInterval: 10,
                labels: {
                    enabled: false
                },
                minorTickWidth: 0,
                tickLength: 50,
                tickWidth: 5,
                tickColor: &#39;white&#39;,
                zIndex: 6,
                stops: [

                    [0, &#39;#f06&#39;],
                    [0.101, &#39;#f03&#39;],
                    [0.201, &#39;#e10&#39;],
                    [0.301, &#39;#c30&#39;],
                    [0.401, &#39;#a50&#39;],
                    [0.501, &#39;#870&#39;],
                    [0.601, &#39;#690&#39;],
                    [0.701, &#39;#4b0&#39;],
                    [0.801, &#39;#2d0&#39;],
                    [0.901, &#39;#0f0&#39;],
                    [1, &#39;#fff&#39;]
                ]
            },
            // other options, including series data, go here
            series: [{
                data: chartData,
                dataLabels: {
                    format: &#39;&lt;div style=&quot;text-align:center&quot;&gt;&lt;span style=&quot;font-size:12px&quot;&gt;{y}%&lt;/span&gt;&lt;br/&gt;&#39;,
                    borderWidth: 0,
                    y: -20
                },
                tooltip: {
                    enabled: false
                    /*valueSuffix: &#39; km/h&#39;*/
                },
                borderWidth: 0,
                color: Highcharts.getOptions().colors[0],
                radius: &#39;100%&#39;,
                innerRadius: &#39;80%&#39;,
            }]
        };
        return options;
    }

    /*debugger;*/
    $(function () {
        debugger;
     
        // Define your data sets here
        var dataSet1 = [20];
        var dataSet2 = [10];
        var dataSet3 = [5];

        // Define an array of data sets
        var dataSets = [dataSet1, dataSet2, dataSet3];

        // Iterate over the data sets and create a new chart for each one
        for (var i = 0; i &lt; dataSets.length; i++) {
            // Create a new container element for the chart
            var $chartContainer = $(&#39;&lt;div&gt;&#39;).appendTo(&#39;#chart-container&#39;);

            // Get the chart options for this data set
            var chartOptions = getChartOptions(dataSets[i]);

            // Create the chart using Highcharts
            Highcharts.chart($chartContainer[0], chartOptions);

            
        }
    });

<!-- language: lang-html -->

&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/highcharts-more.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.highcharts.com/modules/solid-gauge.js&quot;&gt;&lt;/script&gt;

&lt;div id=&quot;chart-container&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

I want to show charts in bootstrap row. Just 3 in one line as shown in image.
Please help me to align these dynamic charts .

答案1

得分: 1

需要在每个图表容器中添加col类。

演示: http://jsfiddle.net/BlackLabel/h92kdmqf/ <br />

英文:

You need to add col class to each charts container.

Demo: http://jsfiddle.net/BlackLabel/h92kdmqf/ <br />

huangapple
  • 本文由 发表于 2023年4月4日 17:00:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定