JustPy中HighMap数据标签异常旋转问题求助
JustPy中HighMap数据标签旋转异常的解决方法
我在JustPy中展示HighMap地图可视化时,遇到一个问题:地图本身并未旋转,但数据标签呈现旋转状态;将地图旋转90度后,标签反而显示为正常对齐状态。
原代码
import justpy as jp my_chart_def = """ { chart: { map: 'custom/europe', borderWidth: 1 }, title: { text: 'Nordic countries' }, subtitle: { text: 'Demo of drawing all areas in the map, only highlighting partial data' }, legend: { enabled: false }, series: [{ name: 'Country', data: [ ['is', 1], ['no', 1], ['se', 1], ['dk', 1], ['fi', 1] ], dataLabels: { enabled: true, color: '#FFFFFF' }, }] } """ def chart_test(): wp = jp.WebPage() wp.head_html = """ <script src="https://code.highcharts.com/maps/9.2.2/highmaps.js"></script> <script src="https://code.highcharts.com/mapdata/custom/europe.js"></script> """ my_chart = jp.HighCharts(a=wp, classes='m-2 p-2 border w-1/2 h-screen', options=my_chart_def) my_chart.options.chart.type = 'map' my_chart.options.series[0].name = 'Test chart' my_chart.options.title.text = 'Data' return wp jp.justpy(chart_test)
问题效果

旋转90度后的正常效果

解决方法
这个问题源于HighMaps的dataLabels默认会继承地图投影的旋转属性,部分自定义地图的投影设置会导致标签旋转异常。无需旋转整个地图,只需在dataLabels配置中显式设置rotation: 0,强制标签保持水平对齐即可。
修改后的代码
import justpy as jp my_chart_def = """ { chart: { map: 'custom/europe', borderWidth: 1 }, title: { text: 'Nordic countries' }, subtitle: { text: 'Demo of drawing all areas in the map, only highlighting partial data' }, legend: { enabled: false }, series: [{ name: 'Country', data: [ ['is', 1], ['no', 1], ['se', 1], ['dk', 1], ['fi', 1] ], dataLabels: { enabled: true, color: '#FFFFFF', rotation: 0 // 强制设置标签旋转角度为0 }, }] } """ def chart_test(): wp = jp.WebPage() wp.head_html = """ <script src="https://code.highcharts.com/maps/9.2.2/highmaps.js"></script> <script src="https://code.highcharts.com/mapdata/custom/europe.js"></script> """ my_chart = jp.HighCharts(a=wp, classes='m-2 p-2 border w-1/2 h-screen', options=my_chart_def) my_chart.options.chart.type = 'map' my_chart.options.series[0].name = 'Test chart' my_chart.options.title.text = 'Data' return wp jp.justpy(chart_test)
内容的提问来源于stack exchange,提问作者wy1189
相关产品推荐
相关产品推荐

