node.js "Usage of deprecated field: 'series'" 在使用 c3 图表制作工具时

node.js "Usage of deprecated field: 'series'" while using c3 chart maker

我正在按照这个 github 项目的说明使用 c3 chart maker:https://github.com/ashleydavis/nodejs-chart-rendering-example

我想从 .csv 数据创建图表,但是当我 运行 图表下方的代码为空时,我收到此消息:"Usage of deprecated field: 'series' ".

const c3ChartMaker = require('c3-chart-maker')

const inputFilePath = "./test_file.csv"
const chartDefinitionFile = "./chart.json"
const outputFilePath = "./chart.png"

c3ChartMaker(inputFilePath, chartDefinitionFile, outputFilePath)
   .then(() => {
      console.log('done')
   })
   .catch(err => {
      console.error(err)
   })

我用这个例子测试你的代码:https://github.com/ashleydavis/c3-chart-maker 我在示例文件夹中使用 example-chart.jsonexample-data.csv,这是我的代码:

const c3ChartMaker = require('c3-chart-maker')

const inputFilePath = "./example-data.csv"
const chartDefinitionFile = "./example-chart.json"
const outputFilePath = "./example-js.png"


c3ChartMaker(inputFilePath, chartDefinitionFile, outputFilePath)
   .then(() => {
      console.log('done')
   })
   .catch(err => {
      console.error(err)
   })

当我 运行 此代码向我显示此图像时:

在我的控制台上我有这条消息:

Usage of deprecated field: 'series'.
done 

我阅读了 node_modules\c3-chart-maker 目录中的 index.js 代码并找到了一些东西:

if (chart.series) { // THIS SECTION IS DEPRECATED.
        console.error("Usage of deprecated field: 'series'.");

        if (!chart.data.columns) {
            chart.data.columns = [];
        }

        var series = Object.keys(chart.series);
        var dataFrame = new dataForge.DataFrame(data);
        series.forEach(seriesName => {
            var dataSeries = chart.series[seriesName];
            if (Sugar.Object.isString(inputData) && seriesName !== "x") {
                dataFrame = dataFrame.parseFloats(dataSeries).bake();
            }

            chart.data.columns.push(
                [seriesName].concat(
                    dataFrame.getSeries(dataSeries)
                        .select(v => v === undefined ? null : v)
                        .toArray()
                )
            )
        });
    }

您看到此错误日志:Usage of deprecated field: 'series'. 因为在 example-chart.json 文件中我们有这一行 json:

"series": {
        "x": "Date",
        "Close": "Close",
        "Volume": "Volume"
    },

series 已弃用。