我正在使用JQPlot在页面上绘制图表。我正在绘制带有标记点的折线图。我想更改标记点的颜色。
我需要每个标记点具有不同的颜色。是否可以?
预先感谢大家的回复。
这是我的代码:
//In order to use keyboard highlight of the coordinates please click somewhere inside the Result frame.
$(document).ready(function() {
// Some simple loops to build up data arrays.
var cosPoints = [];
for (var i = 0; i < 2 * Math.PI; i += 2) {
cosPoints.push([i, Math.cos(i)]);
}
var plot3 = $.jqplot('chart', [cosPoints], {
cursor: {
show: true,
showTooltip: true,
showTooltipGridPosition: true,
// showTooltipDataPosition: false,
showTooltipUnitPosition: false,
useAxesFormatters: false,
// showVerticalLine : true,
followMouse: true
},
title: 'Line Style Options',
// Series options are specified as an array of objects, one object
seriesDefaults: {
markerRenderer: $.jqplot.MarkerRenderer,
markerOptions: {
color: 'red'
}
}
});
$('#chart').bind('jqplotDataClick', function(ev, seriesIndex, pointIndex, data) {
alert(data);
});
var counter = -1; //to start from the very first on first next click, on prev click it will start from last -- and this is how we want it
$('#buttonPrev').bind("click", function() {
counter--;
DoSomeThing(plot3);
});
$('#buttonNext').bind("click", function() {
counter++;
DoSomeThing(plot3);
});
$(document).keydown(function(e) {
if (e.keyCode == 37) {
$('#buttonPrev').click();
}
else if (e.keyCode == 39) {
$('#buttonNext').click();
}
});
function GetColors() {
var colors = ["red","blue","red","blue"];
return colors;
}
function DoSomeThing(plot) {
// *** highlight point in plot ***
//console.log(" sth "+ plot.series[0].data[1][1]);
var seriesIndex = 0; //0 as we have just one series
var data = plot.series[seriesIndex].data;
if (counter >= data.length) counter = 0;
else if (counter < 0) counter = data.length - 1;
var pointIndex = counter;
var x = plot.axes.xaxis.series_u2p(data[pointIndex][0]);
var y = plot.axes.yaxis.series_u2p(data[pointIndex][1]);
console.log("x= " + x + " y= " + y);
var r = 5;
var drawingCanvas = $(".jqplot-highlight-canvas")[0]; //$(".jqplot-series-canvas")[0];
var context = drawingCanvas.getContext('2d');
context.clearRect(0, 0, drawingCanvas.width, drawingCanvas.height); //plot.replot();
context.strokeStyle = "#000000";
context.fillStyle = "#FFFF00";
context.beginPath();
context.arc(x, y, r, 0, Math.PI * 2, true);
context.closePath();
context.stroke();
context.fill();
}
});