首页 > 解决方案 > 如何隐藏 Django Chartit 图表的 xAxis 和 yAxis 标题?

问题描述

我想在一个小图表中隐藏 x/y 轴标题。我尝试从中删除xAxisyAxis字段chart_options,但结果相同。有人可以帮忙吗?

   return Chart(
        datasource=blockpivotdata,
        series_options=[{
            'options': {
                'type': 'line',
                'stacking': False
            },
            'terms': {
                'date': [
                    'num',
                ]
            }
        }],
        chart_options={
            'title': {
                'text': 'Block Count Chart'},
            'xAxis': {
                'title': {
                    'text': 'Date'}},          <<<< this one
            'yAxis': {
                'title': {
                    'text': 'Blocks'}},        <<<< and this one
            'legend': {
                'enabled': False},
            'credits': {
                'enabled': False}},
    )

顺便说一句,我正在使用Django version 2.0,django-chartit 0.2.9Python 3.7.0.

标签: pythondjango

解决方案


后来,我找到了一个解决方案,只想在这里粘贴以防万一有人需要。

    chart_options={
        'title': {
            'text': 'Your Title'
        },
        'xAxis': [
            {
                'title': {
                    'text': 'Date',
                    'style': {
                        'display': 'none'
                    }
                },
                'labels': {
                    'enabled': True
                }
            },
            {
                'title': {
                    'text': 'Date',
                    'style': {               <<<< 
                        'display': 'none'    <<<< use this to hide axis title
                    }
                },
                'labels': {
                    'enabled': False
                },
                'lineColor': 'transparent',
                'tickLength': 0,
            }
        ],
        'yAxis': [
            {
                'title': {
                    'text': 'Blocks',
                    'style': {
                        'color': '#70b3ef'
                    }
                },
                'labels': {
                    'enabled': False
                },
            },
            {
                'title': {
                    'text': 'Total Diff'
                },
                'labels': {
                    'enabled': False
                }
            }
        ],
        'legend': {
            'enabled': False
        },
    }

你可以在这里看到一个活生生的例子:https ://grinexplorer.net


推荐阅读