我正在尝试基于基于数据点的线图和面积图的组合。
在图1中,Y轴显得笨拙,带有许多刻度。有没有一种方法可以将这些刻度设置为在y轴上为“ 3”。对于任何数据点,该值均应保持不变,刻度应始终为3
在图2中,还有一条额外的水平线,在0以下。我有什么办法可以避免它,所以参考线总是从0开始,而不是在0以下。
沙盒链接:https://codesandbox.io/s/react-line-chart-n9g6o?file=/src/LineChart.js
import * as React from "react";
import Highcharts from "highcharts";
import HighchartsReact from "highcharts-react-official";
import HC_exporting from "highcharts/modules/exporting";
HC_exporting(Highcharts);
function LineChart(props) {
let chartOptions = {
chart: {
type: "line",
height: props.height
},
legend: {
align: "center",
verticalAlign: "bottom",
x: 0,
y: 0
},
tooltip: {
shared: true,
useHTML: true,
formatter: function() {
let self = this;
let formattedString = "<small></small><table>";
self.points.forEach(elem => {
formattedString +=
'<tr><td style="color: {series.color}">' +
elem.series.name +
": </td>";
formattedString +=
'<td style="text-align: right"><b>' +
elem.y +
" (" +
elem.point.ts +
")</b></td></tr>";
});
return formattedString;
}
},
colors: props.legendColor,
xAxis: {
visible: true,
step: 1,
tickInterval: 6,
categories: props.categories
},
yAxis: {
visible: true,
step: 1,
tickInterval: 1,
title: {
enabled: true,
text: "Value",
style: {
fontWeight: "100"
}
}
},
plotOptions: {
column: {
dataLabels: {
enabled: true,
crop: false,
overflow: "none"
}
},
line: {
marker: {
enabled: false
}
}
},
series: props.chartData
};
return <HighchartsReact highcharts={Highcharts} options={chartOptions} />;
}
export default LineChart;
答案 0 :(得分:1)
在图1中,Y轴显得笨拙,带有许多刻度。有办法吗 可以将这些刻度设置为的位置在y轴上可以为“ 3”。这应该 对于任何数据点保持恒定,滴答应始终为3
使用tickAmount
属性:
yAxis: {
tickAmount: 3,
..
}
API参考: https://api.highcharts.com/highcharts/yAxis.tickAmount
在图形2中,还有一条额外的水平线,在0以下。 我有什么办法可以避免它,所以引用总是从0开始 而不是行数低于0。
是的,例如,您可以设置softMax
属性。如果只有0个值,Highcharts将无法计算轴比例。
yAxis: {
softMax: 1,
...
}