【问题标题】:Scale graph in angular以角度缩放图
【发布时间】:2021-09-10 06:27:15
【问题描述】:

我正在开发一个角度应用程序。我需要在我的应用程序中使用图表,为此我在我的应用程序中使用 highcharts 库。我需要一个图表,如附图所示。

此图表的比例范围为 0 到 5,数据使用标志/框绘制

我无法在高位图表网站或任何其他角度库中找到此类图表。我怎么能有这个图表?请帮忙。

【问题讨论】:

    标签: angular highcharts angular9 angular10


    【解决方案1】:

    您可以使用 Highstock 的旗帜系列。下面的示例还包含标志的防冲突逻辑。

    Highcharts.chart('container', {
        chart: {
            ...,
            events: {
                render: function() {
                    const points = this.series[0].points;
    
                    points.forEach(function(point, i) {
                        if (points[i + 1] && point.plotX + point.graphic.width > points[i + 1].plotX) {
                            const translateY = point.graphic.translateY - point.graphic.height - 10;
    
                            points[i + 1].graphic.attr({
                                anchorX: points[i + 1].plotX,
                                anchorY: point.graphic.anchorY + point.graphic.height + 10,
                                translateY: translateY
                            });
                        }
                    });
                }
            }
        },
        series: [{
            type: 'flags',
            fillColor: null,
            showInLegend: false,
            colorByPoint: true,
            allowOverlapX: true,
            stackDistance: false,
            data: [{
                x: 1.7,
                title: '1.7'
            }, {
                x: 1.8,
                title: '1.8'
            }, {
                x: 2.1,
                title: '2.1'
            }, {
                x: 2.5,
                title: '2.5'
            }, {
                x: 2.5,
                title: '2.5'
            }],
            shape: 'flag'
        }]
    });
    

    现场演示: https://jsfiddle.net/BlackLabel/eg0oxr4t/

    文档: https://www.highcharts.com/docs/stock/flag-series

    【讨论】:

    • 我会在一段时间内对此进行测试并进行更新。谢谢
    • 您能解释一下标志是如何变色的吗?
    • 如果两个标志的值相同,比如 2.5,我们的代码中有两个标志。如果我单击或悬停在上面的标志上,它就会消失。有什么办法可以避免吗?
    • 嗨@julie,您可以通过fillColor 属性为每个标志定义单独的颜色,例如:jsfiddle.net/BlackLabel/cyvnk78m
    • 避免移动标志的最简单解决方案是在 x 值上添加一些小值。示例:jsfiddle.net/BlackLabel/obc2z6ea
    猜你喜欢
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    • 2018-04-04
    • 1970-01-01
    相关资源
    最近更新 更多