首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HIghlighter在PieChart : jQplot中的应用

HIghlighter在PieChart : jQplot中的应用
EN

Stack Overflow用户
提问于 2013-01-17 08:03:43
回答 2查看 9.9K关注 0票数 4

我想在PieChart中使用荧光笔功能。我的代码是

代码语言:javascript
复制
function device_ownership_graph(titleOfGraph, corporateOwned,
        corporateShared, employeeOwned) {

    var arrCorporateOwned = [ 'Corporate-Owned', corporateOwned ];
    var arrCorporateShared = [ 'Corporate-Shared', corporateShared ];
    var arrEmployeeOwned = [ 'Employee-Owned', employeeOwned ];

    $.jqplot.config.enablePlugins = true;
    /*Here we construct graph*/
    $.jqplot('device_ownership_graph', [ [ arrCorporateOwned, arrCorporateShared, arrEmployeeOwned ] ], {
        title : {
            text : titleOfGraph, // title for the plot,
            show : true,
            fontSize : 14,
            textColor : '#808080',
            textAlign : 'center'
        },
        seriesColors : [ "#00b0f0", "#ffc000", "#92d050"],
        seriesDefaults : {
            // Make this a pie chart.
            renderer : jQuery.jqplot.PieRenderer,
            shadow: false,
            rendererOptions : {
                // Put data labels on the pie slices.
                // By default, labels show the percentage of the slice.
                showDataLabels : true,
                startAngle: 90,
                sliceMargin: 1,
                //highlightMouseOver: true
                highlightMouseDown: true

            }
        },
        legend : {
            renderer : $.jqplot.PieLegendRenderer,
            show : true,
            rendererOptions : {
                numberRows : 1,
                numberColumns : 3,
                disableIEFading : false
            },
            location : 'n',
            placement : 'outsideGrid',
            marginTop : '0px',
            marginBottom : '0px'
        },
        grid : {
            drawGridlines: false,
            show : true,
            background : 'transparent',
            borderWidth : 1,
            shadow : false
        },
        highlighter: {
            showTooltip: true,
            tooltipFade: true
        }

    });
    $('#device_ownership_graph .jqplot-data-label').css('color', '#000000');

    $('#device_ownership_graph').bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data) { alert('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);}); 
}

问题

当鼠标在切片上移动事件时,我在两个不同的浏览器中得到了两个不同的错误。

铬:-

代码语言:javascript
复制
Uncaught TypeError: Cannot read property 'formatter' of undefined jqplot.highlighter.min.js:57

莫兹拉:-

代码语言:javascript
复制
q._xaxis._ticks[0] is undefined

还有一个问题,当我使用highlightMouseDown: true时,它的工作状态(显示警告),但是当我使用highlightMouseOver: true时,它不起作用。

,我的代码做错了什么?请帮帮我,

最新情况:2013年1月22日

我想要荧光笔的行为,因为它在BarGraph中工作。我在给定的代码中使用了alert(),但该代码仅用于高公升的测试。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-18 10:28:50

您所得到的两个错误都是指同一个问题。jqplot.highlighter.min.js中的这一行是:

代码语言:javascript
复制
var w=q._xaxis._ticks[0].formatter;

Chrome无法访问formatter属性,因为q._xaxis._ticks是未定义的(如火狐中所报告的)。

解决方案(受How to display tooltips on jqplot pie chart启发)是将以下代码添加到seriesDefaults配置中:

代码语言:javascript
复制
highlighter: {
    show: true,
    formatString:'%s', 
    tooltipLocation:'sw', 
    useAxesFormatters:false
}

在您的例子中,seriesDefaults看起来应该是:

代码语言:javascript
复制
seriesDefaults:{
    // Make this a pie chart.
    renderer : jQuery.jqplot.PieRenderer,
    shadow: false,
    rendererOptions : {
        // Put data labels on the pie slices.
        // By default, labels show the percentage of the slice.
        showDataLabels : true,
        startAngle: 90,
        sliceMargin: 1,
        highlightMouseOver: true
        //highlightMouseDown: true
    },
    highlighter: {
        show: true,
        //formatString:'%s', 
        //tooltipLocation:'sw', 
        useAxesFormatters:false
    }
}

重要的是将useAxesFormatters设置为false。饼图没有轴,因此先前关于q._xaxis._ticks未定义的错误。

请注意,当您不再使用formatString -based工具提示时,您可能需要注释掉的alert和-based属性。

编辑:

我假设您指的是该页面中的突出显示类型:http://www.jqplot.com/deploy/dist/examples/barTest.html

在最近的highlighter配置中,您目前拥有:

代码语言:javascript
复制
highlighter: {
    showTooltip: true,
    tooltipFade: true
}

如果您只想要高亮显示效果而不想使用工具提示,请将showTooltip设置为false。然后删除绑定到jqplotDataHighlight事件的代码行。这将确保突出显示效果。

票数 10
EN

Stack Overflow用户

发布于 2016-03-09 14:48:14

前面的答案不适用于我:原来,如果包括jqplot.cursor,它将打破饼图。

要使它再次工作,需要有游标:

代码语言:javascript
复制
{ show: false }

作为饼图的一部分,seriesDefaults选项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14374544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档