amCharts中x轴的标签缺失

问题描述 投票:1回答:1

似乎数字计数标签(2、4等)被隐藏在我的图表中。

不确定为什么我没有在代码中的任何地方专门设置隐藏这些。

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>

编辑:

我可以在上面的演示中看到,它可以正常工作(Q2和Q4标签在其他地方都对我隐藏了)。

然而,此fiddle展示了我的经验。

我所看到的:

enter image description here

javascript html amcharts amcharts4
1个回答
0
投票

标签密度由轴渲染器中的minGridDistance属性控制,如in the documentation所述。如果要显示更多标签,则需要将此值设置为较小的值。

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

下面的演示:

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>
© www.soinside.com 2019 - 2024. All rights reserved.