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

关于图表的回归曲线,维度只能是linear类型吗?怎样为Cat类型的维度添加回归曲线呢??? #2571

Closed
jing1810 opened this issue Jun 12, 2020 · 1 comment
Labels

Comments

@jing1810
Copy link

    <html>
      <head>
        <meta charset="UTF-8">
        <title>Netflix 公司市值增长</title>
      </head>
      <body>
        <div id="container" />
        <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g2-3.5.11/dist/g2.min.js"></script>
        <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.data-set-0.10.2/dist/data-set.min.js"></script>
        <script>
        const data = [
  { year: '南宁', value: 10 },
  { year: '西安', value: 20 },
  { year: '榆林', value: 50 },
  { year: '汉中', value: 40 },
  { year: '咸阳', value: 50 },
  { year: '四川', value: 20 },
  { year: '北京', value: 25 },
  { year: '天津', value: 70 },
  { year: '上海', value: 120 },
  { year: '深圳', value: 140 },
  { year: '香港', value: 80 },
  { year: '澳门', value: 250 },

];

const chart = new G2.Chart({
  container: 'container',
  forceFit: true,
  height: 500,
  padding: [ 20, 20, 50, 60 ]
});
//回归曲线数据设置
// const ds = new DataSet();
// const dv = ds.createView().source(data);
// dv.transform({
//   type: 'regression',
//   method: 'polynomial',
//   fields: [ 'year', 'value' ],
//   bandwidth: 0.1,
//   as: [ 'Year', 'Value' ]
// });

chart.scale('year', {
  type: 'cat'
});

const view1 = chart.view();
view1.source(data);
view1.interval().position('year*value').opacity(1);
//回归曲线视图
// const view2 = chart.view();
// view2.axis(false);
// view2.source(dv);
// view2.line().position('Year*Value').style({
//   stroke: '#969696',
//   lineDash: [ 3, 3 ]
// })
// .tooltip(false);

chart.render();
        </script>
      </body>
    </html>
@hustcc
Copy link
Member

hustcc commented Jan 29, 2021

这个需要你理解一下回归曲线的含义。回归曲线必然是对一个指标趋势的拟合,那如果对于分类的 cat,回归拟合的含义是什么呢?

@hustcc hustcc added the Invalid label Jan 29, 2021
@hustcc hustcc closed this as completed Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants