Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成的图没办法水平居中啊 #98

Open
lovelyJason opened this issue May 2, 2023 · 2 comments
Open

生成的图没办法水平居中啊 #98

lovelyJason opened this issue May 2, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@lovelyJason
Copy link

Describe the bug
svg元素和他的父元素宽度是一致,设置flex或者margin: 0 auto都没办法水平居中;
Screenshot
image

image

How to reproduce

<div class="posts-chart" style="width: 800px;">
    <svg class="line-chart"></svg>
</div>
const svg = document.querySelector('.posts-chart .line-chart');
// chartXkcd.Line 创建一个折线图
const lineChart = new chartXkcd.Line(svg, {
    //图表的标题
    title: '文章归档统计图',
    // 图表的 x 标签
    xLabel: '日期',
    // 图表的 y 标签
    yLabel: '文章篇数',
    // 需要可视化的数据
    data: {
        // x 轴数据
        labels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
        // y 轴数据
        datasets: [{
            // 第二组数据
            label: '篇数',
            data: [0, 1, 30, 70, 80, 100, 50, 80, 40, 150],
        }],
    },
    // 可选配置以自定义图表的外观
    options: {
        // 自定义要在 y 轴上看到的刻度号(默认为 3)
        yTickCount: 3,
        // 指定要放置图例的位置
        legendPosition: chartXkcd.config.positionType.upLeft
    }
});

Additional context
Add any other context about the problem here.

@lovelyJason lovelyJason added the bug Something isn't working label May 2, 2023
@timqian
Copy link
Owner

timqian commented May 3, 2023

可以参考下 star-history 是怎么居中的:https://star-history.com/#star-history/star-history&Date

@lovelyJason
Copy link
Author

可以参考下 star-history 是怎么居中的:https://star-history.com/#star-history/star-history&Date

嗯是我设错了样式, 目前好像是宽高无法定义的问题, 好像是固定比例4/3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants