jqplot - Limiting point labels displayed to just 1 series

风流意气都作罢 提交于 2019-12-11 08:27:27

问题


using jqPlot, is it possible to limit the point labels to just one series? See screenshot below! What I would like displayed is just the values above the "Actual" bar. The "mean" and "Planned" should'nt display!

Thanks!

Here's my code

    <script type="text/javascript">
        $(document).ready(function () {

        $.jqplot.config.enablePlugins = true;

        var trendline = [60000, 70000, 110000, 80000];
        var planned = [70000, 90000, 120000, 100000,];
        var actual = [80000, 80000, 150000, 120000];
        var xAxis = ['Jan', 'Feb', 'Mar', 'Apr'];

        $(function() {  
            $.jqplot('chartDiv', [planned, actual, trendline], BarChart());
        });


        function BarChart()
        {
            var optionsObj = {
                title: '',
                axes: {
                     xaxis: {
                        renderer: $.jqplot.CategoryAxisRenderer,
                        ticks: xAxis,                
                    },
                    yaxis: {
                        tickOptions: { showMark: false, formatString: "%'d" },                       
                    },
                },

                legend: {
                    show: true,
                }, 

                grid: { 
                    borderColor: "#dad5d1",
                    background: "#dad5d1",
                    drawGridlines: false,
                    shadow: false
                },

                series: [

                    {label:'Planned',renderer:$.jqplot.BarRenderer},
                    {label: 'Actual',renderer:$.jqplot.BarRenderer},
                        {label: 'Mean',


                    pointLabels: {
                        show: true,
                        },

                        renderer:$.jqplot.LineRenderer,
                            lineWidth:4,
                            markerOptions:{
                                color: "#d87d12",
                                size:12,
                        }}
                    ],

                seriesColors: [ "#ada195", "#4a4541", "#ff9619"],

                seriesDefaults:{
                    shadow: false,

                    rendererOptions:{
                       barPadding: 0,
                       barMargin: 10,
                       barWidth: 25
                   }

                },  
            };
            return optionsObj;
        }
});

</script>

回答1:


This actually looks like a bug in the point labels plugin. You can work around it by disabling the values in the seriesDefault (show:false) and then turning them on for the series you desire:

          series: [
             {label:'Planned',renderer:$.jqplot.BarRenderer},
             {label: 'Actual',renderer:$.jqplot.BarRenderer},
             {label: 'Mean',
              pointLabels: {
                show: true,
              },
              renderer:$.jqplot.LineRenderer,
                lineWidth:4,
                markerOptions:{
                  color: "#d87d12",
                  size:12,
              }}
           ],


           seriesDefaults:{
                pointLabels:{show:false},                    
                shadow: false,
                rendererOptions:{
                   barPadding: 0,
                   barMargin: 10,
                   barWidth: 25
               }
            }, 


来源:https://stackoverflow.com/questions/9807451/jqplot-limiting-point-labels-displayed-to-just-1-series

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!