简体   繁体   English

amCharts 中 x 轴缺失的标签

[英]Labels missing off x Axis in amCharts

It seems like even number counted labels (2, 4 etc) are being hidden in my chart.似乎偶数计数的标签(2、4 等)被隐藏在我的图表中。

Unsure why as I haven't specifically set the hide these anywhere in the code.不确定为什么,因为我没有在代码中的任何地方专门设置隐藏这些。

Demo :演示

 var chart = am4core.create("dataChart", am4charts.XYChart); chart.data = [{ "xValue": "Q1", "yValue": 6 }, { "xValue": "Q2", "yValue": 7 }, { "xValue": "Q3", "yValue": 3 }, { "xValue": "Q4", "yValue": 2 }, { "xValue": "Q5", "yValue": 9 }]; /* Create axes */ var theXAxis = chart.xAxes.push(new am4charts.CategoryAxis()); theXAxis.dataFields.category = "xValue"; /* Create value axis */ var theYAxis = chart.yAxes.push(new am4charts.ValueAxis()); theYAxis.renderer.labels.template.disabled = true; /* Create series */ var series1 = chart.series.push(new am4charts.LineSeries()); series1.dataFields.valueY = "yValue"; series1.dataFields.categoryX = "xValue"; series1.bullets.push(new am4charts.CircleBullet()); series1.tooltipText = "{valueY} / 10"; series1.fill = "#2c3e96"; series1.fillOpacity = .3; series1.stroke = "#4967fa"; /* Create a cursor */ chart.cursor = new am4charts.XYCursor();
 #dataChart{ width: 100%; height: 500px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://www.amcharts.com/lib/4/core.js"></script> <script src="https://www.amcharts.com/lib/4/charts.js"></script> <script src="https://www.amcharts.com/lib/4/themes/animated.js"></script> <div id="dataChart"></div>

Edit:编辑:

I can see in the demo above, it works (Q2 and Q4 labels are hidden for me everywhere else).我可以在上面的演示中看到,它有效(Q2 和 Q4 标签对我来说在其他任何地方都隐藏了)。

This fiddle here however, showcases what I'm experiencing.然而,这里的小提琴展示了我正在经历的事情。

What I'm seeing:我所看到的:

在此处输入图片说明

The label density is controlled by the minGridDistance property in the axis renderer, as mentioned in the documentation .标签密度由轴渲染器中的minGridDistance属性控制,如文档中所述 You'll want to set this to a smaller value if you want to show more labels.如果您想显示更多标签,您需要将其设置为较小的值。

theXAxis.renderer.minGridDistance = 30; //adjust as needed

Demo below:演示如下:

 var chart = am4core.create("dataChart", am4charts.XYChart); chart.data = [{ "xValue": "Q1", "yValue": 6 }, { "xValue": "Q2", "yValue": 7 }, { "xValue": "Q3", "yValue": 3 }, { "xValue": "Q4", "yValue": 2 }, { "xValue": "Q5", "yValue": 9 }]; /* Create axes */ var theXAxis = chart.xAxes.push(new am4charts.CategoryAxis()); theXAxis.dataFields.category = "xValue"; theXAxis.renderer.minGridDistance = 30; /* Create value axis */ var theYAxis = chart.yAxes.push(new am4charts.ValueAxis()); theYAxis.renderer.labels.template.disabled = true; /* Create series */ var series1 = chart.series.push(new am4charts.LineSeries()); series1.dataFields.valueY = "yValue"; series1.dataFields.categoryX = "xValue"; series1.bullets.push(new am4charts.CircleBullet()); series1.tooltipText = "{valueY} / 10"; series1.fill = "#2c3e96"; series1.fillOpacity = .3; series1.stroke = "#4967fa"; /* Create a cursor */ chart.cursor = new am4charts.XYCursor();
 #dataChart { width: 300px; height: 500px; }
 <script src="https://www.amcharts.com/lib/4/core.js"></script> <script src="https://www.amcharts.com/lib/4/charts.js"></script> <script src="https://www.amcharts.com/lib/4/themes/animated.js"></script> <div id="dataChart"></div>

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

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