简体   繁体   English

为什么标签不显示在图表上?

[英]Why labels don't display on the chart?

I'm working on a project with Angular 4 and AmCharts. 我正在使用Angular 4和AmCharts进行项目。 I need to display a simple label on the chart, in the top left corner. 我需要在图表的左上角显示一个简单的标签。

My config code for the chart is as follow: 我的图表配置代码如下:

this.chart = this.AmCharts.makeChart("chart", {
    type: "stock",
    theme: "light",
    addClassNames: true,
    fontFamily: "Teko",
    fontSize: 18,
    mouseWheelZoomEnabled: false,
    titles: [{
        bold: true,
        color: "#FF0000",
        text: "PCS/Min"
    }],
    allLabels: [{
        bold: true,
        text: "PCS/Min",
        color: "#000000",
        x: 20,
        y: 20
    }],
    dataSets: [{
        color: "#93B7BE",
        fieldMappings: [{
            fromField: "y",
            toField: "y"
        }],
        dataProvider: data,
        categoryField: "date",
    }],
    panels: [{
        title: "PCS/Min",
        stockGraphs: [{
            id: "g1",
            valueField: "y",
            lineThickness: 2,
            fillColors: "#ebfffb",
            fillAlphas: 0.1,
            periodValue: "Average"
        }],
        stockLegend: {
            enabled: false,
            valueTextRegular: "PCS/Min"
        }
    }],
    panelsSettings: {
        marginLeft: 25,
        marginRight: 25,
        marginTop: 0,
        marginBottom: 0
    }
  });

Unfortunately, the label and, as you can see on the screenshot, the title of the chart, do not display. 不幸的是,没有显示标签和图表标题,如您在屏幕截图中所见。 Can anyone please help me with this? 谁能帮我这个忙吗? Thank you for the support! 谢谢你的支持!

FYI: I've hidden part of the config code that is not important for this question. 仅供参考:对于该问题,我已经隐藏了配置代码中不重要的部分。

在此处输入图片说明

allLabels and titles are set at the panel level in an AmCharts Stock Chart, not at the top level. allLabelstitles是在AmCharts股票图表中的panel级别而不是顶层设置的。 Just move those definitions down and they'll work. 只需将这些定义下移即可使用。

 var data = [] generateChartData(); function generateChartData() { var firstDate = new Date(); firstDate.setHours(0, 0, 0, 0); firstDate.setDate(firstDate.getDate() - 2000); for (var i = 0; i < 2000; i++) { var newDate = new Date(firstDate); newDate.setDate(newDate.getDate() + i); var value = Math.round(Math.random() * (30) + 100); data[i] = ({ "date": newDate, "y": value }); } } AmCharts.makeChart("chart", { type: "stock", theme: "light", addClassNames: true, fontFamily: "Teko", fontSize: 18, mouseWheelZoomEnabled: false, dataSets: [{ color: "#93B7BE", fieldMappings: [{ fromField: "y", toField: "y" }], dataProvider: data, categoryField: "date", }], panels: [{ title: "PCS/Min", titles: [{ bold: true, color: "#FF0000", text: "PCS/Min" }], allLabels: [{ bold: true, text: "PCS/Min", color: "#000000", x: 20, y: 20 }], stockGraphs: [{ id: "g1", valueField: "y", lineThickness: 2, fillColors: "#ebfffb", fillAlphas: 0.1, periodValue: "Average" }], stockLegend: { enabled: false, valueTextRegular: "PCS/Min" } }], panelsSettings: { marginLeft: 25, marginRight: 25, marginTop: 0, marginBottom: 0 } }); 
 #chart { width: 100%; height: 300px; } 
 <script src="https://www.amcharts.com/lib/3/amcharts.js"></script> <script src="https://www.amcharts.com/lib/3/serial.js"></script> <script src="https://www.amcharts.com/lib/3/amstock.js"></script> <script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script> <link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" /> <script src="https://www.amcharts.com/lib/3/themes/light.js"></script> <div id="chart"></div> 

Also note that there is a title property for the panel as well which will render on top of the chart area rather than inside it, but it needs a stockLegend enabled for that to work. 还要注意,面板也有一个title属性,该属性将在图表区域的顶部而不是在图表区域的顶部呈现,但是它需要启用stockLegend才能起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM