简体   繁体   English

如何在echarts中画一条线

[英]How to draw a line in echarts

I have created a simple echart in Vue.我在 Vue 中创建了一个简单的 echart。 The chart should display the amount of a said thing in the span of one month.该图表应显示一个月内所说事物的数量。 I managed to setup the y-axis and x-axis values, but I can't seem to draw a line, let's say if I have an amount of 50 in one month.我设法设置了 y 轴和 x 轴的值,但我似乎无法画一条线,假设我一个月内有 50 个。 This is how it looks now visually: https://imgur.com/a/m1RCPfA这是它现在的外观: https://imgur.com/a/m1RCPfA

Here is my html:这是我的 html:

<div class="chart-wrapper">
     <chart :options="chartOptionsLine"></chart>
  </div>

and here is my js:这是我的js:

data() {
    return {
chartOptionsLine: {
  xAxis: {
    data: [
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20",
      "21",
      "22",
      "23",
      "24",
      "25",
      "26",
      "27",
      "28",
      "29",
      "30",
      "31"
    ]
  },
   tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          }
        },
  yAxis: {
    data: [
      "1k",
      "5k",
      "10k"
    ],
  },
  series: [
    {
      type: "line",
      data: [10000]
    }
  ],
  title: {
    text: "Monthly Stock Prices",
    x: "center",
    textStyle: {
      fontSize: 24
    }
  },
  color: ["#127ac2"]
}
    }
  }
}

Why is my line not displaying and how can I display it?为什么我的行不显示,我该如何显示?

You are confusing yAxis and series .您混淆yAxisseries You do not need to add yAxis data, just put it into series data as an array.您不需要添加 yAxis 数据,只需将其作为数组放入系列数据中即可。

xAxis: {
    data: [1, 2, 3 ,4, 5, 6, 7]
},
title: {
    text: "Monthly Stock Prices",
    x: "center",
    textStyle: {
        fontSize: 24
    }
},
color: ["#127ac2"],
yAxis: {
    type: 'value'
},
tooltip: {
    formatter: '{b}: {c}'
},
series: [{
    data: [820, 932, 901, 934, 1290, 1330, 1320],
    type: 'line',
    smooth: true
}]

I hope it will be helpful for you.我希望它对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM