Dex*_*ter 3 javascript highcharts highstock
我正在使用HighStock版HighCharts在图表中创建一系列数据.我在条形图的顶部有一个直方图上的烛台图.烛台点是可点击的.我想在他们刚刚点击的烛台图表上添加一个标记.
以下是我尝试过的一些代码:
// create the chart
chart = new Highcharts.StockChart({
chart: {
renderTo: 'container',
alignTicks: false
},
rangeSelector: {
selected: 1
},
title: {
text: 'DJIA Historical'
},
yAxis: [{
title: {
text: 'OHLC'
},
height: 300,
lineWidth: 2
}, {
title: {
text: 'Volume'
},
top: 400,
height: 100,
offset: 0,
lineWidth: 2
}, {
title: {
text: 'MACD'
},
top: 520,
height: 100,
offset: 0,
lineWidth: 1
}],
series: [{
type: 'candlestick',
name: 'DJIA',
data: ohlc,
events: {
click: function(event) {
console.log(chart);
chart.series[6].setData(event.point);
}
},
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Histogram',
pointPadding: 0,
groupPadding: 0,
data: histogram,
yAxis: 2,
color: '#666666'
}, {
type: 'line',
name: 'MACD',
pointPadding: 0,
groupPadding: 0,
data: macd,
yAxis: 2,
color: '#0000FF'
}, {
type: 'line',
name: 'Signal',
pointPadding: 0,
groupPadding: 0,
data: signal,
yAxis: 2,
color: '#000000'
}, {
type: 'flags',
name: 'Active Point',
data: [],
onSeries: ohlc,
shape: 'squarepin'
}]
});
})
Run Code Online (Sandbox Code Playgroud)
该图表不会抛出任何JavaScript错误,但它不会创建标记.至少,它没有显示出来.我想基本上让它在他们点击的烛台上绘制旗帜.如果他们点击另一个点,我想删除旧标志并在新点上绘制一个新标志.我认为最好通过添加和删除系列中的数据来完成,但没有太多运气.
任何有关这方面的帮助将不胜感激!
首先,我们非常感谢您理解您的问题.从我对你的问题的最了解,试试这个(假设5是你的旗帜系列的索引,你的代码似乎是使用索引6?!)
click: function(event) {
this.chart.series[5].addPoint({
x: event.point.x,
title: 'hey you clicked me'
});
}
Run Code Online (Sandbox Code Playgroud)
我的小巧代码@ http://jsfiddle.net/U2Z2x/1/
因为你似乎只对显示1个标志感兴趣,因为你正确地使用了setData,这似乎是你最好的选择,只是一个catch,setData需要一个数组,你传递一个值,也就是点的格式需要稍微重做旗帜类型系列
click: function(event) {
this.chart.series[5].setData([{
x: event.point.x,
title: 'hey you clicked me'
}]);
Run Code Online (Sandbox Code Playgroud)
小提琴更新@ http://jsfiddle.net/U2Z2x/2/