Ric*_*cha 6 html javascript jquery highcharts
我已经在我的项目中实现了一个图表并且运行良好.现在我想在一个特定的动态上添加一个点X-Axis onclick.
这是迄今为止我尝试过的小提琴. 小提琴演示
和代码
plotOptions: {
series: {
cursor: 'ns-resize',
point: {
events: {
drag: function(e) {},
drop: function() {
var y_val = Highcharts.numberFormat(this.y, 2);
var x_val = Highcharts.numberFormat(this.x, 2);
updater(y_val, x_val);
console.log(options.series[1].data);
}
}
},
Run Code Online (Sandbox Code Playgroud)
现在有一种方法可以X-axis在点击上添加一个点.例如,如果我们点击之间10%-20%,那么15%应该在X轴上添加一个点.它也应该附在表格中.
感谢帮助
嗨,这可能是你的目标没有完全实现的另一种方式,但我给你一些想法,你如何实现我已经使用cookie来实现这一目标
你的头应该看起来像
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="Scripts/jquery.cookies.2.2.0.js" type="text/javascript"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
Run Code Online (Sandbox Code Playgroud)
这是你的HTML
<table id="datatable" style="float:left;">
<thead>
<tr>
<th>X Axis</th>
<th>Y Axis</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我没有在你的表格中列出你必须要做的事情
现在这应该是你的脚本
<script>
window.onload = function () {
var val;
var cat_array1; var cat_array2;
var data_variables = [0, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1];
/*global window: false */
if ($.cookie("cat_array1")) {
var cookie = unescape($.cookie('cat_array1'))
cat_array1 = cookie.split(',')
var cookie1 = unescape($.cookie('cat_array2'))
cat_array2 = cookie1.split(',')
}
else {
var cat_array1 = ['10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'];
var cat_array2 = ['5%', '10%', '15%', '20%', '25%', '30%', '35%', '40%', '45%', '50%'];
$.cookie("cat_array1", cat_array1.join(','));
$.cookie("cat_array2", cat_array1.join(','));
}
function regenrate() {
options = {
chart: {
renderTo: 'container',
animation: false,
events: {
click: function () {
alert('click');
}
}
},
xAxis: {
categories: cat_array1
},
plotOptions: {
series: {
cursor: 'ns-resize',
point: {
events: {
drag: function (e) {
},
drop: function () {
var y_val = Highcharts.numberFormat(this.y, 2);
var x_val = Highcharts.numberFormat(this.x, 2);
updater(y_val, x_val);
console.log(options.series[1].data);
},
click: function () { var options = this.options; alert('Person who like' + options.name + ' ' + options.personName); }
}
},
stickyTracking: true
},
column: {
stacking: 'normal'
}
},
tooltip: {
yDecimals: 2
},
series: [{
name: 'main',
data: data_variables,
draggableY: false,
dashable: true
}, {
name: 'modifier',
data: [0, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1],
draggableY: true
}]
}
function updater(yv, xv) {
//console.log("Y :" + yv + ",X: " + xv);
var num = xv.match(/^\d+/);
console.log(num);
options.series[1].data[num] = parseInt(options.series[1].data[num].y.toFixed(1));
var chart = new Highcharts.Chart(options);
$('#b' + num).html(yv);
console.log(yv + ", " + xv);
return false;
}
var chart = new Highcharts.Chart(options);
var yAxis = chart.xAxis[0];
var onYaxisRedraw = function () {
for (var tickPos in yAxis.ticks) {
if (tickPos != '-1') {
var $element = $(yAxis.ticks[tickPos].label.element);
$element.unbind('click');
$element.click(function (e) {
// cat_array1.push(1,parseInt(e.toElement.innerHTML.replace('%', '')) + 5 + '%');
var aa = jQuery.inArray(e.toElement.innerHTML, cat_array1);
cat_array1.splice(parseInt(aa + 1), 0, parseInt(e.toElement.innerHTML.replace('%', '')) + 5 + '%');
// options.xAxis = cat_array1;
$.cookie("cat_array1", cat_array1.join(','));
// chart.series[0].setData(null,true);
// var chart = new Highcharts.Chart(options);//$('#container').highcharts().xAxis[0].update()
window.location.reload();
// regenrate()
});
}
}
}
onYaxisRedraw();
yAxis.redraw(onYaxisRedraw);
}
regenrate();
}
</script>
Run Code Online (Sandbox Code Playgroud)
Explaination :-
Run Code Online (Sandbox Code Playgroud)
您有要求应该在10%和20%之间点击,但我认为这不可能实现虽然我不确定:)
但是如果你点击10%然后在那个数组你可以添加5然后可以做到这一点我希望你能理解我的观点
如果您单击数组中的10%然后将添加15%,则这是另一种方式
好的,我希望你能理解我的观点............
| 归档时间: |
|
| 查看次数: |
1556 次 |
| 最近记录: |