我在使用highcharts-more
中的極座標選項時出現了一個很奇怪的問題。這是什麼樣子...... Highcharts極座標圖不能正確連線
下面是我完整的代碼(它被包裹在一個陣營組件)
import React from 'react'
import PropTypes from 'prop-types'
import { Card, CardHeader, CardText, CircularProgress } from 'material-ui'
import ReactHighcharts from 'react-highcharts'
import HighchartsMore from 'highcharts-more'
import colors from '../../../colors'
HighchartsMore(ReactHighcharts.Highcharts)
const styles = {
textAlignLeft: {
textAlign: 'left'
},
loadingCardText: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}
}
const View = ({data1, data2, data3, data4, loading, hasEtfBeenSelected, highchartsAreaThreshold}) => {
if (!hasEtfBeenSelected) {
return (<div />)
}
let config = {
credits: false,
chart: {
polar: true,
type: 'area'
},
title: {
text: null
},
pane: {
size: '80%',
startAngle: 22.5
},
colors: [
colors.color1, colors.color2, colors.color3, colors.color4
],
xAxis: {
categories: data1.map(x => x[0]),
tickmarkPlacement: 'on',
lineWidth: 0
},
plotOptions: {
series: {
threshold: highchartsAreaThreshold
}
},
yAxis: {
gridLineInterpolation: 'polygon',
lineWidth: 0,
min: highchartsAreaThreshold,
startOnTick: false,
tickAmount: 5
},
tooltip: {
shared: true,
valuePrefix: '$'
},
legend: {
align: 'right',
verticalAlign: 'top',
y: 70,
layout: 'vertical'
},
series: [
{
name: 'Data1',
data: data1,
pointPlacement: 'on',
marker: {
enabled: false
},
fillOpacity: 0.2,
lineWidth: 1
},
{
name: 'Data2',
data: data2,
pointPlacement: 'on',
marker: {
enabled: false
},
fillOpacity: 0.2,
lineWidth: 1
},
{
name: 'Data3',
data: data3,
pointPlacement: 'on',
marker: {
enabled: false
},
fillOpacity: 0.2,
lineWidth: 1
},
{
name: 'Data4',
data: data4,
pointPlacement: 'on',
marker: {
enabled: false
},
fillOpacity: 0.2,
lineWidth: 1
}
]
}
if (loading) {
return (<div>
<Card>
<CardHeader title='Spreads' style={styles.textAlignLeft} />
<CardText style={styles.loadingCardText}>
<CircularProgress size={70} thickness={5} />
</CardText>
</Card>
</div>)
}
return (
<div>
<Card>
<CardHeader title='Spreads'
style={styles.textAlignLeft} />
<CardText>
<ReactHighcharts config={config} />
</CardText>
</Card>
</div>
)
}
View.propTypes = {
data1: PropTypes.array,
data2: PropTypes.array,
data3: PropTypes.array,
data4: PropTypes.array,
loading: PropTypes.bool,
hasEtfBeenSelected: PropTypes.bool,
highchartsAreaThreshold: PropTypes.number
}
export default View
highchartsAreaThreshold
被設置爲所有數據的最小(使圖表顏色爲負數據)。這很奇怪,因爲這個確切的代碼實際上昨天工作。所以它是隨機的。我不知道我在做什麼錯。
編輯:下面是一些示例數據(data1..data4所有像這樣):
data1:
Array[8]
0: 0.01
1: 0
2: -0.007
3: 0.014
4: -0.001
5: 0.021
6: 0
7: 0.01
data2:
Array[8]
0: 0.04
1: 0.02
2: 0.003
3: 0.031
4: -0.03
5: -0.006
6: -0.03
7: 0.04
作爲建議我只使用一個簡單的數組代替2D矢量的陣列的嘗試,但我得到同樣的結果。
你的數據是什麼樣的?它是否分類? –
不是。它必須是? – coolboyjules
如果數據未在折線圖中排序,我注意到了類似的行爲 – coolboyjules