javascript - flotr2 - 单击时更改点颜色

标签 javascript flotr2

是否可以更改 Flotr2 中点(线性图)的填充颜色?

我的代码:

<script>
    /* globals*/
    var lineColor = '#717171';
    var baseLineColor = '#a3d06e';
    var titleText = []; /* [title1, title2,...] */
    var xticks = [];  /* [ [0.9, ""], [1, "strValue1"], ..., [n, strValueN], [n+0.1, ""] ] */

    var title = document.getElementById('title');
    var data = [ /* the chart data */
        [1, 2],
        [2, 3],
        [3, 3],
        [4, 4],
        [5, 5],
        [6, 5],
        [7, 5],
        [8, 2],
        [9, 3],
        [10, 3],
        [11, 4],
        [12, 5],
        [13, 5],
        [14, 5],
        [15, 5],
        [16, 2],
        [17, 3],
        [18, 3],
        [19, 4],
        [20, 5],
        [21, 5],
        [22, 5],
        [23, 2],
        [24, 3],
        [25, 3],
        [26, 4],
        [27, 5],
        [28, 5],
        [29, 5],
        [30, 5],
    ];

    var container = document.getElementById('chart');


    /*Test - remove for real data*/
    for(var i=1; i<31; i++){
        xticks.push([i, ("label " + i)]);
        titleText[i] = "Title " + i;
    }

    /* chart options */
    var personal = { data : data, /* @data@ */
        lines : { show : true, fill : false, color: lineColor, lineWidth: 4},
        points : { show : true, color: lineColor, radius: 20, fillColor:'#ff0000'}
    };

    var baseline = { data: [[-50,3],[50,3]],
        mouse: {track: false},
        lines : { show : true, fill : false, color: baseLineColor, lineWidth: 4}
    }


    setTimeout(setDimentions, 300);



    function setDimentions(){
        var w = window.innerWidth * 0.8;
        var h = window.innerWidth * 0.45;
        container.style.width = w + "px";
        container.style.height = h + "px";

        drawChart();
    }

    function drawChart(){
        var f = Flotr.draw(container, [baseline, personal],
                {
                    resolution: 2, HtmlText: true,
                    xaxis : { ticks: xticks /* @xticks@ */, tickDecimals: true, min:0.8, max: (data.length+0.2)/*@xmax@*/ },
                    yaxis : { ticks: [1,2,3,4,5], tickDecimals: true, min:0.9, max: 5.1 },
                    mouse : { track : true, sensibility: 10, trackFormatter: showTitle}
                });
    }

    function showTitle(point){
        title.innerHTML = titleText[parseInt(point.x)];
    }

最佳答案

使用以下选项应该足够了:

  mouse : {
    track : true,
    relative : true,
    lineColor : '#FF00FF',
    fillColor : '#0000FF'
  },

我在这里放了一个演示: http://jsfiddle.net/93by5/1/

关于javascript - flotr2 - 单击时更改点颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20327428/

相关文章:

javascript - Flotr2 - 安全销毁图形元素以及与该元素绑定(bind)的所有事件

javascript - Flotr2 颜色不起作用

javascript - 当使用 cookie 重新加载页面时,如何让 Vimeo 视频从中断处继续播放?

javascript - Wordpress ACF 包含 input.js 不工作

javascript - 使用 Joi,要求两个字段之一为非空

javascript - 如何在 Javascript 中不包含属性

javascript - 带有条形图日期的 Flotr2 错误

javascript - 在 Internet Explorer 6 中访问 SELECT 的值

javascript - 谷歌地图地理编码问题