【问题标题】:jqplot not show label end pointsjqplot不显示标签端点
【发布时间】:2017-06-08 07:43:31
【问题描述】:

当我使用 jqplot 绘制图表时,图表的两个端点都没有显示标签,我不知道为什么。请帮忙

这是我的代码(自包含代码,已加载所有资源)

<html>
<head>
</head>
<body>
    <input id="dashboardForm:j_idt49:4:hiddenChartData" type="text" name="dashboardForm:j_idt49:4:hiddenChartData" value="{&quot;data&quot;:[[843,1312,745,683,832,829,772,740,792,672,550,323]],&quot;dateFull&quot;:[[1,&quot;01/06&quot;],[2,&quot;02/06&quot;],[3,&quot;03/06&quot;],[4,&quot;04/06&quot;],[5,&quot;05/06&quot;],[6,&quot;06/06&quot;],[7,&quot;07/06&quot;],[8,&quot;08/06&quot;],[9,&quot;09/06&quot;],[10,&quot;10/06&quot;],[11,&quot;11/06&quot;],[12,&quot;12/06&quot;]],&quot;tick&quot;:[[1,&quot;01/06&quot;],[2,&quot;02/06&quot;],[3,&quot;03/06&quot;],[4,&quot;04/06&quot;],[5,&quot;05/06&quot;],[6,&quot;06/06&quot;],[7,&quot;07/06&quot;],[8,&quot;08/06&quot;],[9,&quot;09/06&quot;],[10,&quot;10/06&quot;],[11,&quot;11/06&quot;],[12,&quot;12/06&quot;]]}" class="soluongdonhangngay170" style="display:none;"> 
    <div style="height: 550px" class="soluongdonhangngay170170" />


<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/org.richfaces.resources/javax.faces.resource/org.richfaces/jquery.js"></script> 
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jquery.jqplot.js?ln=js"></script>    
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.dateAxisRenderer.js?ln=js"></script>   
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.categoryAxisRenderer.js?ln=js"></script>   
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.logAxisRenderer.js?ln=js"></script>    
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.canvasTextRenderer.js?ln=js"></script> 
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.canvasAxisTickRenderer.js?ln=js"></script> 
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.canvasAxisLabelRenderer.js?ln=js"></script>    
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.highlighter.js?ln=js"></script>    
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.pointLabels.js?ln=js"></script>    
<script type="text/javascript" src="http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.enhancedLegendRenderer.js?ln=js"></script> 
<script>
jQuery(function(){
    var labels = ["Đơn Hàng Theo Ngày"];
  alert(jQuery(".soluongdonhangngay170").val());
  displayLineChartWithToggleLegend($(".soluongdonhangngay170").val(),$(".soluongdonhangngay170170"), labels, "Số Lượng Đơn Hàng Ngày");
});

function displayLineChartWithToggleLegend(data, target, label, chartTitle){
    if(data === "") return;
    var chartJsonData = $.parseJSON(data);
    var dataPlot = chartJsonData.data;
    var ticks = chartJsonData.tick;
    var showPointLabel = true;
    if(chartJsonData.data.length > 4){
        showPointLabel = false;
    }
    target.jqplot(dataPlot, {
        title: chartTitle,
        animate: true,
        axesDefaults: {
            labelRenderer: $.jqplot.CanvasAxisLabelRenderer
        },
        seriesDefaults: {
            showMarker: true
        },
        legend: {
            show: true,
            renderer: $.jqplot.EnhancedLegendRenderer,
            placement: "outsideGrid",
            labels: label,
            location: "ne",
            rowSpacing: "5px",
            rendererOptions: {
                // set to true to replot when toggling series on/off
                // set to an options object to pass in replot options.
                seriesToggle: 'normal',
                seriesToggleReplot: {resetAxes: true}
            }
        },
        axes: {
            xaxis: {
                label: 'Date',
                ticks: ticks,          
                tickInterval: 20,
                tickOptions: {
                    showGridline: false,
                    angle: -60,
                    fontFamily: 'Helvetica',
                    fontSize: '8pt'
                },                
            }
        },
        grid: {
            drawBorder: false,
            shadow: false,
            // background: 'rgba(0,0,0,0)'  works to make transparent.
            background: "white"
        },
        series: [
            {
                pointLabels: {
                    show: showPointLabel
                },
                rendererOptions: {
                    // speed up the animation a little bit.
                    // This is a number of milliseconds.
                    // Default for a line series is 2500.
                    animation: {
                        speed: 2000
                    },
                    smooth: true
                }
            }
        ]
    });

    target.bind('jqplotDataMouseOver', function(ev, seriesIndex, pointIndex, data) {
        var idx = seriesIndex;
        $('tr.jqplot-table-legend').removeClass('legend-row-highlighted');  
        $('tr.jqplot-table-legend').children('.jqplot-table-legend-label').removeClass('legend-text-highlighted');
        $('tr.jqplot-table-legend').eq(idx).addClass('legend-row-highlighted');
        var dateFull = chartJsonData.dateFull;
        $(this).find(".jqplot-title").html(dateFull[data[0] - 1][1] + " - " + data[1]);
        $('tr.jqplot-table-legend').eq(idx).children('.jqplot-table-legend-label').addClass('legend-text-highlighted'); 
    });

    target.bind('jqplotDataUnhighlight', function(ev, seriesIndex, pointIndex, data) {
        $('tr.jqplot-table-legend').removeClass('legend-row-highlighted');  
        $('tr.jqplot-table-legend').children('.jqplot-table-legend-label').removeClass('legend-text-highlighted');
        $(this).find(".jqplot-title").html(chartTitle);        
    });
}
</script>
</body>
</html>

【问题讨论】:

  • 你能做一个小提琴或codepen吗?
  • @shramee:我似乎无法让它在 jsfiddle 上工作(因为我的资源不是 https)。但是,我编辑了我的帖子,将代码放在了独立的形式中。您可以将其复制到a.html,然后运行它。谢谢

标签: javascript jquery jqplot


【解决方案1】:

我之前遇到过这个问题,但是我的 X 轴值是数字,并通过从最大值添加大约 20% 的比率(调整)来修复它,以获得更多空间,这就是诀窍在这里我建议你再添加一个X 值(X 刻度)中的值没有 Y 值(刻度)中的相关值以扩展(添加更多空间)X 轴(如果您对 Y 轴有相同的问题,请使用相同的技术)看看@987654321 @

<input id="dashboardForm:j_idt49:4:hiddenChartData" type="text" name="dashboardForm:j_idt49:4:hiddenChartData" value="{&quot;data&quot;:[[843,1312,745,683,832,829,772,740,792,672,550,323]],&quot;dateFull&quot;:[[1,&quot;01/06&quot;],[2,&quot;02/06&quot;],[3,&quot;03/06&quot;],[4,&quot;04/06&quot;],[5,&quot;05/06&quot;],[6,&quot;06/06&quot;],[7,&quot;07/06&quot;],[8,&quot;08/06&quot;],[9,&quot;09/06&quot;],[10,&quot;10/06&quot;],[11,&quot;11/06&quot;],[12,&quot;12/06&quot;],[13,&quot;13/06&quot;]],&quot;tick&quot;:[[1,&quot;01/06&quot;],[2,&quot;02/06&quot;],[3,&quot;03/06&quot;],[4,&quot;04/06&quot;],[5,&quot;05/06&quot;],[6,&quot;06/06&quot;],[7,&quot;07/06&quot;],[8,&quot;08/06&quot;],[9,&quot;09/06&quot;],[10,&quot;10/06&quot;],[11,&quot;11/06&quot;],[12,&quot;12/06&quot;]**,[13,&quot;13/06&quot;]**]}" class="soluongdonhangngay170" style="display:none;"> 

希望对您有所帮助。

【讨论】:

  • 这就是答案。非常感谢。
【解决方案2】:

您需要在 target.jqplot(dataPlot, {...}) 调用中使用此代码启用荧光笔...

    highlighter: {
        show: true,
        sizeAdjust: 7.5
    },

使用此 CSS 设置工具提示的样式;)

.jqplot-highlighter-tooltip {
    background: #fff;
    box-shadow: 0 0 3px 1px rgba(0,0,0,0.5);
    padding: 2px 3px;
}

希望有所帮助;)

【讨论】:

    【解决方案3】:

    我遇到了类似的问题,数据标签没有显示在我的趋势边缘。

    一种解决方案是将 jqplot.pointLabels.js 文件中的 edgeTolerance 从默认值 (-10) 增加到所需值:

       $.jqplot.PointLabels = function(options) {
    
          ...
    
        // prop: edgeTolerance
        // Number of pixels that the label must be away from an axis
        // boundary in order to be drawn.  Negative values will allow overlap
        // with the grid boundaries.
        this.edgeTolerance = -1000;
       
          ...
        
        $.extend(true, this, options);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多