Vue-chartjs: Can't turn off bezier curves in line chart.

Created on 22 Jan 2019  路  3Comments  路  Source: apertureless/vue-chartjs

Expected Behavior

Setting line tension to 0 should turn of bezier curves and render straight lines.

Actual Behavior

The line options are not impacting the rendered chart, so even with tension set to 0, the lines are still curved.

Here is the code I am using:

<script>
import { Line } from 'vue-chartjs'

export default {
  extends: Line,
  mounted () {
    // Overwriting base render method with actual data.
    this.renderChart({
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
      datasets: [
        {
          label: 'Data One',
          borderColor: '#f87979',
          fill: false,
          elements: {
            line: {
              tension: 0
            }
          },
          data: [40, 39, 10, 40, 39, 80, 40]
        }
      ]
    }, {responsive: true, maintainAspectRatio: false})
  }
}
</script>

Environment

  • vue.js version: 2.5.17
  • vue-chart.js version: 3.4.0
  • npm version: 6.4.1

Most helpful comment

Oh yeah, you can pass the global options into your local options, too.
Thats right :)

Glad you got it working.

馃憤

All 3 comments

Because you using it wrong.

You can either define the line-tension in a global scope or per dataset.

Dataaset

https://www.chartjs.org/docs/latest/charts/line.html#dataset-properties

Its called lineTension

datasets: [
        {
          label: 'Data One',
          borderColor: '#f87979',
          fill: false,
          lineTension: 0,
          data: [40, 39, 10, 40, 39, 80, 40]
        }
      ]

Global

Or if you want to define it globally
https://www.chartjs.org/docs/latest/configuration/elements.html#line-configuration

Chart.defaults.global.elements.line.tension = 0;

Thanks.

For the record, I also got it working this way:

this.renderChart({
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
      datasets: [
        {
          label: 'CPU usage',
          borderColor: '#f87979',
          fill: false,
          data: [40, 39, 10, 40, 39, 80, 40]
        }
      ],

    },
    {
      responsive: true, maintainAspectRatio: false,
      elements: {
        line: {
          tension: 0
        }
      },
    })

Oh yeah, you can pass the global options into your local options, too.
Thats right :)

Glad you got it working.

馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssuess picture ssuess  路  5Comments

timster picture timster  路  5Comments

kurbar picture kurbar  路  4Comments

LeeLenaleee picture LeeLenaleee  路  3Comments

jacobmischka picture jacobmischka  路  3Comments