【问题标题】:Chart js Bar Time ChartChart js 条形时间图
【发布时间】:2019-02-28 10:41:27
【问题描述】:

在条形时间图中添加数据有两种方式

  1. 当我们在标签中添加日期并将 y 作为数据传递给数据集时

  2. 直接在数据集中添加为 (x,y) 对

第一个完美运行,而第二个不渲染任何东西

var barChartData = {
			labels: [moment().add(1, 'd').toDate(), moment().add(2, 'd').toDate(), moment().add(3, 'd').toDate(), moment().add(4, 'd').toDate(), moment().add(5, 'd').toDate(), moment().add(6, 'd').toDate(), moment().add(7, 'd').toDate()],
			datasets: [{
				label: 'Dataset 1',
				backgroundColor: window.chartColors.red,
				data: [
					Math.random()*100,
					Math.random()*100,
					Math.random()*100,
					Math.random()*100,
					Math.random()*100,
					Math.random()*100,
          Math.random()*100
        ]
      }]    
  }

var barChartData = {
			datasets: [{
				label: 'Dataset 1',
				backgroundColor: window.chartColors.red,
				data: [
					{ x: moment().add(1, 'd').toDate(), y: Math.random()*100 },
					{ x: moment().add(2, 'd').toDate(), y: Math.random()*100 },
					{ x: moment().add(3, 'd').toDate(), y: Math.random()*100 },
					{ x: moment().add(4, 'd').toDate(), y: Math.random()*100 },
					{ x: moment().add(5, 'd').toDate(), y: Math.random()*100 },
					{ x: moment().add(6, 'd').toDate(), y: Math.random()*100 },
					{ x: moment().add(7, 'd').toDate(), y: Math.random()*100 },
				]
			}]

		};

是我做错了什么还是一个错误?

【问题讨论】:

    标签: javascript chart.js bar-chart


    【解决方案1】:

    所有类型的图表都不支持“笛卡尔坐标轴”。条形图是其中一种类型,它支持“径向轴”。

    如果您想在图表中同时使用 (x,y) 轴,​​请选择不同的类型。对 (x,y) 对使用气泡/散点图。

    阅读本文,您将在此处获得更多信息:https://www.chartjs.org/docs/latest/axes/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多