我无法在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上添加指标线?
答案 0 :(得分:1)
@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();
。