简体   繁体   English

删除HighChart图上的间距?

[英]Remove spacing on a HighChart graph?

I have a chart with data that is being pulled from xml file. 我有一个图表,其中包含从xml文件中提取的数据。 And I cannot for some reason get rid of the spacing. 而且由于某种原因,我无法摆脱空白。 If need be I will put together my code and post it on http://jsfiddle.net 如果需要,我将整理我的代码并将其发布在http://jsfiddle.net上

图表间距

***************************SOLUTION:********************************* ***************************解:********************* ************

OK I am sorry I still can't get this to work on JSFiddle, but here is what I did to my code. 好吧,很抱歉,我仍然无法在JSFiddle上使用它,但是这是我对代码所做的。 Hopefull someday this will help someone else. 希望有一天这会帮助别人。

HERE IS MY ORIGINAL CODE: 这是我的原始代码:

$(document).ready(function() {
        var options = {
            chart: {
                renderTo: 'container',
                type: 'column', 
            },
            title: {
                text: 'Donations'
            },
            xAxis: {                    
                categories: [],
                startOnTick: false,
            },
            yAxis: {
                title: {
                    text: 'Money $'
                }

            },              
            plotOptins: {
                column: {
                    size:'150%'
                }
            },
            legend: {
            enabled: false,           
        },
            series: []
        };

        // Load the data from the XML file 
        $.get('data.xml', function(xml) {
            // Split the lines
            var $xml = $(xml);              
            // push categories
            $xml.find('stock symbol').each(function(i, category) {options.xAxis.categories.push($(category).text());    
            });     
            // push series
            $xml.find('stock').each(function(i, series) {
                var seriesOptions = {
                    name: $(series).find('symbol').text(),
                    data: []
                };

                // push data points
                $(series).find('price').each(function(i, point) {
                    seriesOptions.data.push(
                        parseInt($(point).text())
                    );
                });

                // add it to the options
                options.series.push(seriesOptions);
            });
            var chart = new Highcharts.Chart(options);

        });
    });

HERE IS MY NEW CODE: 这是我的新代码:

$(document).ready(function() {
        var options = {
            chart: {
                renderTo: 'container',
                type: 'column',     
            },
            title: {
                text: 'Donations'
            },
            xAxis: {                    
        categories: [],
            },
            yAxis: {
                title: {
                    text: 'Money $'
                }

            },
            plotOptins: {
                column: {
                    size:'150%'
                }
            },
            legend: {
            enabled: false,
        },
            series: []
        };

        // Load the data from the XML file 
        $.get('data.xml', function(xml) {
            // Split the lines
            var $xml = $(xml);

            // push categories
            $xml.find('stock symbol').each(function(i, category) {
                options.xAxis.categories.push(i);                           
            });         
                var seriesOptions = {
                    //name: $(series).find('symbol').text(),
                    data: []
                };
            // push series              
            $xml.find('stock').each(function(i, series) {
                // push data points
                $(series).find('price').each(function(i, point) {
                    seriesOptions.data.push(parseInt($(point).text())
                    );
                });                 
                // add it to the options

            }); options.series.push(seriesOptions);
            var chart = new Highcharts.Chart(options);
        });


    });

The solution is to do with the group padding. 解决方案是与组填充有关。 If you add this to your chart options, it will remove the spacing on the left and on the right. 如果将此添加到图表选项中,它将删除左侧和右侧的间距。

See the example below here where I have added groupPadding: 0 在下面的示例中,我添加了groupPadding:0

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        type: 'column', 
    },
    plotOptions: {
        series: {
            groupPadding: 0
        }
    },
    ...
)};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM