gpt4 book ai didi

javascript - amCharts 中 x 轴上的标签丢失

转载 作者:行者123 更新时间:2023-11-28 03:10:06 25 4
gpt4 key购买 nike

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

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

演示:

        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

最佳答案

标签密度由轴渲染器中的 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>

关于javascript - amCharts 中 x 轴上的标签丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60210584/

25 4 0