Code Monkey home page Code Monkey logo

vue-trend-chart's Introduction

Vue Trend


๐Ÿ’ฟ Installation

npm i vue-trend-chart

๐Ÿš€ Usage

import TrendChart from "vue-trend-chart";

app.use(TrendChart);

Example:

<TrendChart
  :datasets="[
    {
      data: [10, 50, 20, 100, 40, 60, 80],
      smooth: true,
      fill: true
    }
  ]"
  :grid="{
     verticalLines: true,
     horizontalLines: true
  }"
  :labels="{
     xLabels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
     yLabels: 5
  }"
  :min="0">
</TrendChart>

๐Ÿ”ง Props

datasets

Required
Type: Array

Array of objects with properties for each dataset.

grid

Type: Object

Grid properties

labels

Type: Object

Labels properties

min

Type: Number
Default: min value from datasets

max

Type: Number
Default: max value from datasets

padding

Type: String
Default: "5"

If you set a large stroke-width on your lines, you may notice that it gets "cropped" towards the edges. It's similar to "padding" CSS property but without specifying units.

Examples:
"5" apply to all four sides
"5 10" vertical | horizontal
"5 15 10" top | horizontal | bottom
"5 10 15 20" top | right | bottom | left

interactive

Type: Boolean
Default: false

Allows to set onmousemove interaction. Set to true to enable.

โšก Events

mouse-move

Callback function for onmouseover interaction.
Receives an object {index: Number, data: Array} parameter based on current active line.
This function has no effect if interactive isn't set to true.

๐Ÿ“ˆ Dataset Props

Chart line (curve) properties

data

Type: Number|Object

Example: [70, 100, 400, 180, 100] or [{ value: 70 }, { value: 100 }, { value: 400 }, { value: 180 }, { value: 100 }]
For object type you can also add other properties to use them in interactive mode.

className

Type: String

Allows to append custom class to chart line for future styling.

smooth

Type: Boolean
Default: false

Allows the peaks to be 'rounded' out.

stroke

Type: Boolean
Default: true

If false, the line is not drawn for this dataset.

fill

Type: Boolean
Default: false

Allows to fill the area under the line. Set to true to enable.

showPoints

Type: Boolean
Default: false

Allows to show points. Set to true to enable.

#๏ธโƒฃ Grid Props

verticalLines

Type: Boolean
Default: false

Allows to show vertical gridlines. Set to true to enable.

verticalLinesNumber

Type: Number
Default: number of xLabels

Allows to set custom number of vertical gridlines.
This prop has no effect if verticalLines isn't set to true.

horizontalLines

Type: Boolean
Default: false

Allows to show horizontal gridlines. Set to true to enable.

horizontalLinesNumber

Type: Number
Default: number of yLabels

Allows to set custom number of horizontal gridlines.
This prop has no effect if horizontalLines isn't set to true.

๐Ÿ”ค Labels Props

xLabels

Type: Array

X axis labels.
Example: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

yLabels

Type: Number

Number of Y axis labels. Labels text is based on data values.

yLabelsTextFormatter

Type: Function

Allows to format Y axis labels text.
Example: val => "$" + Math.round(val * 100) / 100.
This function has no effect if yLabels prop has no value.

๐ŸŽจ Styling

Just use CSS to style your charts.

Here is an example of a tree structure with available class names:

<svg class="vtc">
  <g class="grid">
    <g class="vertical">
      <line class="line"></line>
      ...
    </g>
    <g class="horizontal">
      <line class="line"></line>
      ...
    </g>
  </g>

  <g class="labels">
    <g class="x-labels">
      <g class="label">
        <text></text>
      </g>
      ...
    </g>
    <g class="y-labels">
      <g class="label">
        <text></text>
      </g>
      ...
    </g>
  </g>

  <g class="curve">
    <path class="fill"></path>
    <path class="stroke"></path>
    <g class="points">
      <circle class="point"></circle>
      ...
    </g>
  </g>
  ...

  <line class="active-line"></line>
</svg>

๐Ÿ”จ Development

npm install
npm run dev

๐Ÿ’• Contributing

Pull requests are welcome!

๐Ÿ”’ License

MIT

vue-trend-chart's People

Contributors

dependabot[bot] avatar dmtrbrl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vue-trend-chart's Issues

Incorrect formatting xLabels

when I move data label from data()

  data() {
    return {
      ...
      labels: {
        xLabels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        yLabels: 5,
        yLabelsTextFormatter: val => Math.round(val * 100) / 100
      },

to mounted()
like:

  mounted() {
    ...
    this.labels = {        
      xLabels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
      yLabels: 5,
      yLabelsTextFormatter: val => Math.round(val * 100) / 100}
  }

then the bottom label (xLabels) overlaps the chart (changes position/moves up)

image

https://codepen.io/czelsa/pen/gOaQzbP

Changing xLabels doesn't update the HTML

When changing xLabels, by changing it on TrendChartLabels directly or via TrendChart, the HTML doesn't get rerendered.

I build a workaround by calling $forceReload everytime I update it, but there has to be a better solution.

Outdated Axios Peer-Dependency

Hey!
I noticed that the package lists an outdated version of axios as a peer-dependency.
Since some time now npm will install (and thus require) those by default - meaning that having vue-trend-chart anywhere in the dependency-tree prevents users from updating axios altogether.

npm ERR! Found: [email protected]
npm ERR! node_modules/axios
npm ERR!   dev axios@"^0.21.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer axios@"^0.18.0" from [email protected]
npm ERR! node_modules/vue-trend-chart
npm ERR!   vue-trend-chart@"^0.15.3" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Workaround:

npm install axios@latest --save --legacy-peer-deps

Since axios seems to only be included for the demo I'd suggest creating a separate package.json for that.

Cheers!

Can't start the y-axis range from a defined value except 0

I want to modify the y-axis range, want to start it from a defined value like 50 or 100. I tried using yLabelsTextFormatter but it's not plotting the graph in a correct way (means taking the y-axis from 0 only).

Can you please suggest is there any way?

Is it possible to specify the exact position of the horizontal lines?

I would like to show a single horizontal line showing the average value across the data.

Is it possible to configure the position of the horizontal line to do this?

If not, would you be open to a pull request to support this? Can you provide any guidance on how best to achieve this?

Vue 3 Support

Tried to use it with Vue 3. Getting the following error:

vue-trend-chart.esm.js?21e9:723 Uncaught (in promise) TypeError: h is not a function
    at Proxy.render (vue-trend-chart.esm.js?21e9:723)
    at renderComponentRoot (runtime-core.esm-bundler.js?9e79:846)
    at componentEffect (runtime-core.esm-bundler.js?9e79:4280)
    at reactiveEffect (reactivity.esm-bundler.js?0a2b:42)
    at effect (reactivity.esm-bundler.js?0a2b:17)
    at setupRenderEffect (runtime-core.esm-bundler.js?9e79:4263)
    at mountComponent (runtime-core.esm-bundler.js?9e79:4222)
    at processComponent (runtime-core.esm-bundler.js?9e79:4182)
    at patch (runtime-core.esm-bundler.js?9e79:3791)
    at mountChildren (runtime-core.esm-bundler.js?9e79:3975)
render @ vue-trend-chart.esm.js?21e9:723

Needs Typescript support

When using Typescript I get this error:
Could not find a declaration file for module 'vue-trend-chart'. '/node_modules/vue-trend-chart/dist/vue-trend-chart.common.js' implicitly has an 'any' type.

Graph sizes incorrectly in Electron app when programmatically resizing window

In an Electron app, I'm loading up a vue-trend-chart in a Vuetify full-screen dialog.

Initially, I had an issue with the graph loading up at what appears to be a minimum size. I think this was related to displaying it in a transitioning full-screen dialogue where the dialog size was undefined so the graph SVG didn't scale to fit properly. I remedied this by redrawing the graph once the dialog was opened.

Then I re-encountered the issue when programmatically setting the window size in Electron. The graph looks fine by default:
image
and then when you close the dialog containing the graph, press a button to resize the current window, and reopen the dialog to view the graph:
image

EDIT: At this point, manually resizing the electron app window just a pixel will fix the graph and make it display properly, filling up the container size again.

I'm not sure what the problem is here, I know SVG scaling is more awkward than say just having an image.

Is it possible to provide a function to redraw the SVG's or any other way to combat this?

Windows 10
Electron 7.3.0
Vue-Trend-Chart 0.15.2

vuejs3 compatibility

since chartjs is not compatible with vue3 vue-trend-chart also has some problems when it's used with vue3 like the h function, i solved the h function issue but still see a lot of problems , is there any future fix for this , &thank you

on:mouseMove not working

Hi there,

I'm not sure what if I'm doing something wrong (because your codepen samples don't have this problem) or if this is a bug, but on:mouseMove event isn't being called.

I suspect it's because of this:
https://vuejs.org/v2/guide/components-custom-events.html#Event-Names

Additionally, v-on event listeners inside DOM templates will be automatically transformed to lowercase (due to HTMLโ€™s case-insensitivity), so v-on:myEvent would become v-on:myevent โ€“ making myEvent impossible to listen to.

Vue js hints in console (using non minified version of vue.js) seem to confirm this:

[Vue tip]: Event "mousemove" is emitted in component but the handler is registered for "mouseMove". Note that HTML attributes are case-insensitive and you cannot use v-on to listen to camelCase events when using in-DOM templates. You should probably use "mouse-move" instead of "mouseMove".

The fix for me seems to be change this

        this.$emit(
          "mouseMove",  ////// this should be lowercase to "mousemove"
          this.activeLineParams ? Object.assign({}, this.activeLineParams, {data: data}) : null
        );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.