如何使用JSON本地文件创建ApexCharts(JavaScript)?

发布于 2025-02-10 09:00:57 字数 2051 浏览 2 评论 0 原文

正如标题所说,我想使用我已经事先下载的JSON数据创建ApexChart,

我已经在Internet中搜索了JSON数据使用:

const df = require('data/processed.json');

我已经试图将其称为df ['like'],为y和df ['name'],因为

我想念的东西吗? 或打电话给专栏不会这样做? 我还尝试了DF.Liked和DF.Name,BTW

const df= require('data/processed.json');
var options = {
        chart: {
            height: 230,
            type: 'line',
            toolbar: {
                show: false,
            },
        },
        dataLabels: {
            enabled: false
        },
        stroke: {
            width: 2,
            curve: 'smooth'
        },
        series: {
            name: 'Liked',
            data: df['liked']
        },
        legend: {
            position: 'top',
        },
        xaxis: {
            type: 'string',
            data: df['name'],
            axisBorder: {
                show: false,
            },
            label: {
                style: {
                    color: '#ccc'
                }
            },
        },
        yaxis: {
            show: true,
            // min: 10,
            // max: 70,
            labels: {
                style: {
                    color: '#ccc'
                }
            }
        },
        colors: ['#73b4ff', '#59e0c5'],
        fill: {
            type: 'gradient',
            gradient: {
                shade: 'light',
                gradientToColors: ['#4099ff', '#2ed8b6'],
                shadeIntensity: 0.5,
                type: 'horizontal',
                opacityFrom: 1,
                opacityTo: 1,
                stops: [0, 100]
            },
        },
        markers: {
            size: 5,
            colors: ['#4099ff', '#2ed8b6'],
            opacity: 0.9,
            strokeWidth: 2,
            hover: {
                size: 7,
            }
        },
        grid: {
            borderColor: '#cccccc3b',
        }
    }
    var chart = new ApexCharts(document.querySelector("#unique-visitor-chart"), options);
    chart.render();

enter code here

As the title say, I want to create apexchart using json data that I downloaded beforehand

I already search in internet to get json data use :

const df= require('data/processed.json');

And I already tried to call it df['liked'] as y and df['name'] as x

Is there something I miss?
Or call the column is not gonna do it?
I have also tried df.liked and df.name, btw

const df= require('data/processed.json');
var options = {
        chart: {
            height: 230,
            type: 'line',
            toolbar: {
                show: false,
            },
        },
        dataLabels: {
            enabled: false
        },
        stroke: {
            width: 2,
            curve: 'smooth'
        },
        series: {
            name: 'Liked',
            data: df['liked']
        },
        legend: {
            position: 'top',
        },
        xaxis: {
            type: 'string',
            data: df['name'],
            axisBorder: {
                show: false,
            },
            label: {
                style: {
                    color: '#ccc'
                }
            },
        },
        yaxis: {
            show: true,
            // min: 10,
            // max: 70,
            labels: {
                style: {
                    color: '#ccc'
                }
            }
        },
        colors: ['#73b4ff', '#59e0c5'],
        fill: {
            type: 'gradient',
            gradient: {
                shade: 'light',
                gradientToColors: ['#4099ff', '#2ed8b6'],
                shadeIntensity: 0.5,
                type: 'horizontal',
                opacityFrom: 1,
                opacityTo: 1,
                stops: [0, 100]
            },
        },
        markers: {
            size: 5,
            colors: ['#4099ff', '#2ed8b6'],
            opacity: 0.9,
            strokeWidth: 2,
            hover: {
                size: 7,
            }
        },
        grid: {
            borderColor: '#cccccc3b',
        }
    }
    var chart = new ApexCharts(document.querySelector("#unique-visitor-chart"), options);
    chart.render();

enter code here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑红尘 2025-02-17 09:00:57

尝试使用:

 const df = fetch("./data/processed.json")
        .then(response => {
            return response.json();
        })

的文档

关于获取方式 将在您的JSON上捕获所有数据,并在您的 const df 中使用返回:)

如果要使用 require()查看: https://requirejs.org/

注意:尝试使用很多 console.log() 调试您的JS应用程序。

try to use :

 const df = fetch("./data/processed.json")
        .then(response => {
            return response.json();
        })

A documentation about fetch

This way will catch all data on your json and pu it in your const df by using the return :)

If you want to use require() look about : https://requirejs.org/

NOTE : Try to use a lot console.log() to debug your js app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文