调整html中容器的高度

问题描述 投票:0回答:1

在此处输入图像描述我正在尝试调整破折号容器(白色)的高度,但我似乎不知道该怎么做,这段代码和我将不胜感激任何帮助:

analytics.html:

{% extends 'frontend/base.html' %}
{% load plotly_dash %}

{% block content %}
    <h2>Reports and Analytics</h2>
    <div id="dash-container" style="width: 100%; height: 1200px; overflow: hidden;">  <!-- Adjust container height here -->
        {% plotly_app name="Analytics" %}
    </div>
{% endblock %}

analytics_dash.py:

import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objects as go
from django_plotly_dash import DjangoDash
from .models import UserAction
from django.db.models import Count

# Create a Django Dash application
app = DjangoDash('Analytics')

def load_data():
    actions = UserAction.objects.values('action_type').annotate(count=Count('id'))
    return [action['action_type'] for action in actions], [action['count'] for action in actions]

# Define the layout of the Dash app
app.layout = html.Div([
    dcc.Graph(
        id='user-action-graph',
        style={'width': '100%', 'height': '100%'}  # Use 100% to fill container
    )
], style={'width': '100%', 'height': '1200px'})  # Adjust to match container size

@app.callback(
    Output('user-action-graph', 'figure'),
    [Input('user-action-graph', 'id')]
)
def update_graph(_):
    action_types, counts = load_data()

    fig = go.Figure()

    if not action_types or not counts:
        fig.add_annotation(text="No Activity Data Available Yet", showarrow=False)
    else:
        fig.add_trace(go.Bar(
            x=action_types, 
            y=counts, 
            marker=dict(color='royalblue', line=dict(color='black', width=1))
        ))

    max_count = max(counts) if counts else 5

    fig.update_layout(
        title='User Activities',
        xaxis_title='Action Type',
        yaxis_title='Count',
        yaxis=dict(range=[0, max_count + 2]),
        margin=dict(l=40, r=40, b=40, t=40),
        height=1000,  # Match height with container
    )

    return fig`

我尝试使用最小高度和最大高度调整我自己的 dcc 图表,睾丸,但似乎没有任何东西可以解决问题,我只能设法使容器内的图表更大

python html css django plotly-dash
1个回答
0
投票

我相信这与Python无关,而是与CSS相关。您应该搜索 CSS 样式,例如宽度、最小宽度、高度等。还有它们对于不同值(例如

100%
100vw
)的行为方式。好吧,我有一个给你

© www.soinside.com 2019 - 2024. All rights reserved.