php - Highcharts如何使用列标题作为X轴而不是图例
问题描述
我使用 highcharts 将我的表格转换为折线图,但现在我面临一个问题,我想将列标题作为 x 轴,而不是在图中使用图例。附上表格的代码和截图。我希望我能找到解决这个问题的方法,因为我还是 highcharts 的新手。
{
"title": {
"text": "Performance Review"
},
"subtitle": {
"text": ""
},
"yAxis": {
"title": {
"text": "Number of Products"
},
"labels": {},
"opposite": false,
"reversed": false
},
"xAxis": {
"title": {
"text": "Quarter"
},
"labels": {},
"opposite": false,
"reversed": false
},
"legend": {
"layout": "vertical",
"align": "right",
"verticalAlign": "middle"
},
"credits": {
"enabled": false
},
"plotOptions": {
"series": {
"label": {
"connectorAllowed": false
},
"pointStart": 1,
"animation": false
}
},
"series": [
{
"name": "Quarter 1",
"turboThreshold": 0,
"_colorIndex": 0,
"_symbolIndex": 0
},
{
"name": "Quarter 2",
"turboThreshold": 0,
"_colorIndex": 1,
"_symbolIndex": 1
},
{
"name": "Quarter 3",
"turboThreshold": 0,
"_colorIndex": 2,
"_symbolIndex": 2
},
{
"name": "Quarter 4",
"turboThreshold": 0,
"_colorIndex": 3,
"_symbolIndex": 3
}
],
"responsive": {
"rules": [
{
"condition": {
"maxWidth": 500
},
"chartOptions": {
"legend": {
"layout": "horizontal",
"align": "center",
"verticalAlign": "bottom"
}
},
"_id": "highcharts-amzecb7-4"
}
]
},
"data": {
"csv": "\"Company\";\"Quarter 1\";\"Quarter 2\";\"Quarter 3\";\"Quarter 4\"\n\"A\";24916;24916;11744;30000",
"googleSpreadsheetKey": false,
"googleSpreadsheetWorksheet": false
},
"chart": {
"inverted": false
}
}
解决方案
您需要将 switchRowsAndColumns 属性设置为 true,并将 xAxis 类型设置为类别。您还可以从图表选项中删除系列。
var chart = Highcharts.chart('container', {
"title": {
"text": "Performance Review"
},
"subtitle": {
"text": ""
},
"yAxis": {
"title": {
"text": "Number of Products"
},
"labels": {},
"opposite": false,
"reversed": false
},
"xAxis": {
type: 'category',
"title": {
"text": "Quarter"
},
"labels": {},
"opposite": false,
"reversed": false
},
"legend": {
"layout": "vertical",
"align": "right",
"verticalAlign": "middle"
},
"credits": {
"enabled": false
},
"plotOptions": {
"series": {
"label": {
"connectorAllowed": false
},
"pointStart": 1,
"animation": false
}
},
"responsive": {
"rules": [{
"condition": {
"maxWidth": 500
},
"chartOptions": {
"legend": {
"layout": "horizontal",
"align": "center",
"verticalAlign": "bottom"
}
},
"_id": "highcharts-amzecb7-4"
}]
},
"data": {
switchRowsAndColumns: true,
"csv": "\"Company\";\"Quarter 1\";\"Quarter 2\";\"Quarter 3\";\"Quarter 4\"\n\"A\";24916;24916;11744;30000"
},
"chart": {
"inverted": false
}
});
现场演示:https ://jsfiddle.net/BlackLabel/8f3pve9w/
API:https ://api.highcharts.com/highcharts/data.switchRowsAndColumns
推荐阅读
- excel - excel使用vba在access中导入文本文件
- android - iOS CLLocationManager 未检测到从 Android 发送的 Android 信标库 iBeacon 信号
- python - 重新创建与输入相同的 xml 文件
- r - 用于功能“BoostFit”的包?
- javascript - 如何在 data-id 和输入类型上使用 querySelector
- javascript - 事件发生在时间间隔而不是点击
- django - 清除 Django 缓存
- regex - VBA 正则表达式与其他正则表达式 - 我不明白它为什么这样做?
- python - 为什么两个线程没有同时执行?
- r - R中的简单数据操作任务