jquery - jqPlot 条形图出现问题

标签 jquery jquery-plugins jqplot

我正在使用 jqPlot 创建条形图,但遇到了一些问题。

问题 1:图表上的第一个和最后一个条形图被截断。仅显示一半

问题 2:我不希望我的数据点跨越整个 x 轴。是否不能让数据跨越整个 x 轴?

enter image description here 例如:这就是现在所做的。

这是我传递给它的数据

var chartData = [["19-Jan-2012",2.61],["20-Jan-2012",5.00],["21-Jan-2012",6.00]]

这是我正在使用的jquery。

 // Plot chart
        function PlotChart(chartData, numberOfTicks) {
            $.jqplot.config.enablePlugins = true;
                 var plot2 = $.jqplot('chart1', [chartData], {
                    title: 'Mouse Cursor Tracking',
                     seriesDefaults:{
                         renderer: $.jqplot.BarRenderer,
                         rendererOptions: {
                            barPadding: 1,
                            barMargin: 15,
                            barDirection: 'vertical',
                            barWidth: 50
                        }, 
                        pointLabels: { show: true }
                    },
                    axes: {
                        xaxis: {
                            pad: 0,       // a factor multiplied by the data range on the axis to give the
                            numberTicks: numberOfTicks,
                            renderer:  $.jqplot.DateAxisRenderer,  // renderer to use to draw the axis,
                            tickOptions: {
                                formatString: '%b %#d'   // format string to use with the axis tick formatter
                            }
                        },
                        yaxis: {
                            tickOptions: {
                                formatString: '$%.2f'
                            }
                        }
                    },
                    highlighter: {
                        sizeAdjust: 7.5
                    },
                    cursor: {
                        show: true
                    }
                });
            }

最佳答案

从您希望绘图的外观来看,如果您改用 CategoryAxisRenderer 而不是 DateAxisRenderer,将为您省去很多麻烦。与真实的时间序列相比,CategoryAxisRenderer 更擅长显示离散的数据分组。

var axisDates = ["Jan 19", "Jan 20", "Jan 21"]
var chartData = [2.61,5.00,6.00]

        $.jqplot.config.enablePlugins = true;
             var plot2 = $.jqplot('chart2', [chartData], {
                title: 'Some Plot',
                 seriesDefaults:{
                     renderer: $.jqplot.BarRenderer,
                     rendererOptions: {
                        barPadding: 1,
                        barMargin: 15,
                        barDirection: 'vertical',
                        barWidth: 50
                    }, 
                    pointLabels: { show: true }
                },
                axes: {
                    xaxis: {                            
                            renderer:  $.jqplot.CategoryAxisRenderer,
                            ticks: axisDates
                    },
                    yaxis: {
                        tickOptions: {
                            formatString: '$%.2f'
                        }
                    }
                },
                highlighter: {
                    sizeAdjust: 7.5
                },
                cursor: {
                    show: true
                }
            });

enter image description here

关于jquery - jqPlot 条形图出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9057765/

相关文章:

javascript - 通过 jquery 的表编辑器

jquery - JQPlot - 饼图 - 获取点击的切片颜色

width - jqPlot 条形图宽度

javascript - jQuery 和 AngularJS 不能一起工作

javascript - 背景幻灯片 - 在淡入/淡出之间暂停?

javascript - 基于条件的 jQuery 可拖动还原

jquery - 与 Angular 集成的数据表不显示 Excel、PDF 等导出按钮

javascript - 我正在尝试运行一个简单的 jqplot 示例,但它不会显示,为什么不呢?

jquery - 使用jquery刷新rails项目中的<table>

javascript - jQuery 切换持续时间未设置