Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度高度图面积图中的自定义图例标签_Javascript_Angular_Charts_Highcharts_Angular2 Highcharts - Fatal编程技术网

Javascript 角度高度图面积图中的自定义图例标签

Javascript 角度高度图面积图中的自定义图例标签,javascript,angular,charts,highcharts,angular2-highcharts,Javascript,Angular,Charts,Highcharts,Angular2 Highcharts,我必须在面积图类型中自定义标签符号,就像在折线图类型中一样: 我有以下代码: Highcharts.chart('container', { chart: { type: 'area' }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, plo

我必须在面积图类型中自定义标签符号,就像在折线图类型中一样:

我有以下代码:

Highcharts.chart('container', {
        chart: {
        type: 'area'
    },

    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    plotOptions: {
        series: {
            marker: {
                enabled: false
            }
        }
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});
我的传奇是这样的:

我希望有这个:

我无法编辑css样式,这必须是仅此图表的独家定制

我使用的是angular 7.2,我已经导入了Highchart:

import {Chart} from 'angular-highcharts';

您可以通过手动设置图例符号的宽度和高度来实现这一点。您需要将
squareSymbol
设置为
false
,以允许宽度和高度具有不同的值:

legend: {
    squareSymbol: false,
    symbolHeight: 3,
    symbolWidth: 20
},
比如说

编辑

如果要将符号与文本对齐,请使用
useHTML:true
并设置
行高

  legend: {
    useHTML: true,
    itemStyle: {
      lineHeight: "23px"
    },
    squareSymbol: false,
    symbolHeight: 3,
    symbolWidth: 20
  },

区域.prototype.drawLegendSymbol方法与.prototype.drawLegendSymbol交换。这在纯JS中已经足够了:

Highcharts.seriesTypes.area.prototype.drawLegendSymbol =
Highcharts.seriesTypes.line.prototype.drawLegendSymbol;

在角度视图中,可以通过以下方式包装海图:

(function(factory) {
  if (typeof module === "object" && module.exports) {
    module.exports = factory;
  } else {
    factory(Highcharts);
  }
})(function(Highcharts) {
  Highcharts.seriesTypes.area.prototype.drawLegendSymbol =
    Highcharts.seriesTypes.line.prototype.drawLegendSymbol;
});

文档:

这对标签有效,但对工具提示无效。它有效,但如何用文本将符号居中?@Kabulan0lak现在就完美了。非常感谢你!此处相同:这适用于标签,但对于工具提示是失败的,因为无法执行此操作。我没有
seriesTypes
它是默认的工具提示“符号”,即使对于一行或任何其他系列也是如此。如果要更改此设置,可以在本例中的tooltip.formatter函数行中执行此操作:@Segamoto当然可以。我将编辑我的答案。