javascript - 填充 amCharts 线条路径并删除 yAxes 值

标签 javascript jquery css amcharts amcharts4

我使用 amCharts 来创建这个:

enter image description here

我遇到以下问题:

  1. 我无法让 y 轴标签消失。看完documentation ,我尝试过 theYAxis.disabled = true;
  2. 我希望折线图下方的所有内容都填充为蓝色。目前,我的只显示一条线。我尝试过:

var range = xAxis.axisRanges.create();
range.theXAxis.fill = chart.colors.getIndex(8);
range.theXAxis.fillOpacity = 0.2;

我哪里出错了?

演示:

var chart = am4core.create("dataChart", am4charts.XYChart);

chart.data = [{
    "xValue": "Q1",
    "yValue": 3
}, {
    "xValue": "Q2",
    "yValue": 4
}, {
    "xValue": "Q3",
    "yValue": 7
}, {
    "xValue": "Q4",
    "yValue": 2
}, {
    "xValue": "Q5",
    "yValue": 9
}];

/* Create axes */
var theXAxis = chart.xAxes.push(new am4charts.CategoryAxis());
theXAxis.dataFields.category = "xValue";

// tryin to get line to fill below
//var range = xAxis.axisRanges.create();
//range.theXAxis.fill = chart.colors.getIndex(8);
//range.theXAxis.fillOpacity = 0.2;

/* Create value axis */
var theYAxis = chart.yAxes.push(new am4charts.ValueAxis());
//theYAxis.disabled = true; // . trying to disable . to 1-10 showing here


/* 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";

/* 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>

最佳答案

为了删除标签,您必须直接在轴渲染器上禁用标签,如 documentation 中所述。

theYAxis.renderer.labels.template.disabled = true;

如果您只需要在线下方进行基本填充,请直接在系列上设置fillfillOpacity

series.stroke = "#000088"; //for the line
series.fill = "#000088";  // for the fill
series.fillOpacity = .3;

var chart = am4core.create("dataChart", am4charts.XYChart);

chart.data = [{
    "xValue": "Q1",
    "yValue": 3
}, {
    "xValue": "Q2",
    "yValue": 4
}, {
    "xValue": "Q3",
    "yValue": 7
}, {
    "xValue": "Q4",
    "yValue": 2
}, {
    "xValue": "Q5",
    "yValue": 9
}];

/* Create axes */
var theXAxis = chart.xAxes.push(new am4charts.CategoryAxis());
theXAxis.dataFields.category = "xValue";

// tryin to get line to fill below
//var range = xAxis.axisRanges.create();
//range.theXAxis.fill = chart.colors.getIndex(8);
//range.theXAxis.fillOpacity = 0.2;

/* Create value axis */
var theYAxis = chart.yAxes.push(new am4charts.ValueAxis());
//theYAxis.disabled = true; // . trying to disable . to 1-10 showing here
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 = "#000088";
series1.fillOpacity = .3;
series1.stroke = "#000088";

/* 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>

关于javascript - 填充 amCharts 线条路径并删除 yAxes 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60207055/

相关文章:

html - CSS float-left 防止单词换行

javascript - 如何为移动设备采用下拉菜单?

php - 当没有更多帖子显示时隐藏加载更多按钮

javascript - 计算多个圆片段旋转

jquery - 根据选择隐藏或显示 DIV 的条件 JQuery 表单?

asp.net-mvc-3 - 关于使用jquery ajax返回excel文件的建议

html - 如何让 div 填满所有宽度并像 TR 中的 TDs 一样排成一行?

javascript - 空白字段的默认值

javascript - 使用 jQuery 覆盖 onclick 值

javascript - 使用 canvas + JS 将对象从一个 (x,y) 移动到另一个 (x,y)