【问题标题】:How to set AnyChart Candlestick colors dynamic?如何设置 AnyChart 烛台颜色动态?
【发布时间】:2018-11-07 12:21:45
【问题描述】:

我想动态设置烛台颜色。但我不知道怎么做。

所以我将参数 true 如anychart Doc 所述传递给anychart.stock 构造函数并在带有映射字段的数据集上定义了一个字段颜色 如下所示。

有人得到解决方案吗?

参考 Dok:https://docs.anychart.com/Stock_Charts/Data#individual_point_settings

anychart.onDocumentReady(function() {

    // create a data table
    var table = anychart.data.table('x');
    // add data
    table.addData([{
        'x': '2015-12-24',
        'open': 511.53,
        'high': 514.98,
        'low': 505.79,
        'close': 506.40,
        'fill': '#00FF00'
    }]);

    // create a stock chart
    var chart = anychart.stock(true);

    // create a mapping
    var mapping = table.mapAs({
        'open': 'open',
        'high': 'high',
        'low': 'low',
        'close': 'close',
        'fill': 'fill'
    });

    // add a series using the mapping
    chart.plot(0).candlestick(mapping).name('ACME Corp.');

    // set container id for the chart
    chart.container('container');

    // initiate chart drawing
    chart.draw();
});

【问题讨论】:

    标签: javascript web candlestick-chart anychart


    【解决方案1】:

    您的方法绝对正确!唯一的问题是烛台系列没有“填充”设置,它有上升填充和下降填充。因此,您只需使用这些设置对其进行映射。您可以在下面的评论中根据您的代码检查工作示例。此外,您可以在this article 中了解有关烛台设置的更多信息。

    【讨论】:

    • 非常感谢您。您的解决方案完美运行!使用映射的下降填充,上升填充对我来说一切正常。
    • 补充问题:有没有办法覆盖单个蜡烛的颜色?假设蜡烛是绿色的,但对于某个事件,您想让一根蜡烛变成深绿色
    • @hootnot 是的,有可能!为此,您应该覆盖表中的此点数据。例如,您需要更新日期为 2021-01-01 的点的颜色填充:dataTable.addData([ {x: 2021-01-01, value: 12, fill: 'dark-green'} ])
    • @AnyChartSupport :正如您所建议的,我已在问题中的代码中添加了risingFill 和fallingFill。 'fallingFill' 确实给出了红色蜡烛,但 'risingFill' 给出了橙色蜡烛而不是绿色蜡烛。我错过了什么还是这是一个错误?
    • @hootnot 请联系 support@anychart.com 并提供您的图表代码 sn-p。我们将对其进行审核并根据您的代码给出解决方案。
    【解决方案2】:

    根据anychart的答案,代码变成了代码块中的样子。添加了一根额外的蜡烛,我希望看到一根绿色和一根红色的蜡烛。但只有红色蜡烛根据“fallingFill”正确显示。 “risingFill”未显示绿色蜡烛。

    anychart.onDocumentReady(function() {
    
    // create a data table
    var table = anychart.data.table('x');
    // add data
    table.addData([{
        'x': '2015-12-24',
        'open': 511.53,
        'high': 514.98,
        'low': 505.79,
        'close': 506.40,
        'fallingFill': '#FF0000',
    },
     {
        'x': '2015-12-25',
        'open': 521.53,
        'high': 524.98,
        'low': 515.79,
        'close': 524,    // 516.40, 
        'risingFill': '#00FF00'
    }]);
    
    // create a stock chart
    var chart = anychart.stock(true);
    
    // create a mapping
    var mapping = table.mapAs({
        'open': 'open',
        'high': 'high',
        'low': 'low',
        'close': 'close',
        'risingFill': 'risingFill', 
        'fallingFill': 'fallingFill'
    });
    
    // add a series using the mapping
    chart.plot(0).candlestick(mapping).name('ACME Corp.');
    
    // set container id for the chart
    chart.container('container');
    
    // initiate chart drawing
    chart.draw();
    });
    

    【讨论】:

    • 使第二根蜡烛关闭> 打开使risingFill 工作正常。覆盖两者将始终强制设置颜色。 (@anychart-support:感谢您的反馈)
    猜你喜欢
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 2018-04-06
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多