我无法在AmStockChart上添加指标行
我试图在DataSet属性中添加多个AmStockChart.dataSets,如下所示:
....
firstDataSet.fieldMappings = [
{ fromField: "open", toField: "open" },
{ fromField: "high", toField: "high" },
{ fromField: "low", toField: "low" },
{ fromField: "close", toField: "close" },
{ fromField: "volume", toField: "volume" }
];
....
secondDataSet.fieldMappings = [ { fromField: "value", toField: "value" } ];
....
chart.dataSets = [ firstDataSet, secondDataSet ];
但是在图形初始化后,我只能看到第一个烛台图形。
如何在AmStockChart上添加指标线?
最佳答案
@zeroin告诉我a good solution。无需添加新的DataSet
。您可以使用现有的DataSet
,但可以像下面这样添加新的field
:
// exactly dataSet can be not first
// "indicator_" + i - field name
chart.dataSets[ 0 ].fieldMappings.push({
fromField: "indicator_" + i,
toField: "indicator_" + i
});
然后将计算出的
value
添加到其字段中:for ( var j = 0; j < chart.dataSets[ 0 ].dataProvider.length; j ++ ) {
// calculate value
chart.dataSets[ 0 ].dataProvider[ j ][ "indicator_" + i ] = value.toFixed( 4 );
}
并将新的
StockGraph
添加到StockPanel
:var indicatorGraph = new AmCharts.StockGraph();
indicatorGraph.valueField = "indicator_" + i;
indicatorGraph.useDataSetColors = false;
indicatorGraph.type = "smoothedLine";
stockPanel.addStockGraph( indicatorGraph );
然后呼叫
chart.validateNow();
。关于javascript - 图表上的AmStockChart指标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22448347/