Code Monkey home page Code Monkey logo

frappe-charts-ionic-3's Introduction

Frappe Charts in Ionic 3

Use frappe-charts in Ionic 3 as a custom component

How to use

npm install -g ionic@latest
ionic start frappe-charts-ionic

Install Frappe charts to the project.

npm install [email protected]

Note: since frappe-charts had its major rewrite for v1, we have to indicate the v0.0.7 when installing the package.

Copy the frappe-charts component to your project's components folder. Make sure to import this component in your general component's module /src/components/components.module.ts.

Import the styles in /src/app/app.scss

@import '../../node_modules/frappe-charts/dist/frappe-charts.min';

Lastly, import the component's module to /src/app/page.module.ts. Also, make sure that your app is configured to use the lazy loading feature!

...
import { ComponentsModule } from '../components/components.module';

@NgModule({
	declarations: [...],
	imports: [
		...,
		IonicModule.forRoot(MyApp, {
			preloadModules: true //enable preloading of modules
		}),
		ComponentsModule,
	],
	exports: [...]
})
...

To use it in a page, just provide the data:

...
export class Page {
  public chartParam: any;
  
  constructor(){
    this.chartParam = {
      title: 'Bar chart',
      type: 'bar',
      data: {
        labels: ["12am", "3am", "6am", "9am", "12pm", "3pm", "6pm", "9am"],
        datasets: [
          {
            title: "Some Data",
            color: "light-blue",
            values: [25, 40, 30, 35, 8, 52, 17, -4]
          },
          {
            title: "Another Set",
            color: "violet",
            values: [25, 50, -10, 15, 18, 32, 27, 14]
          }
        ]
      }
    };
  }
}

You should import the Component Module in home page module as well.

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
import { ComponentsModule } from '../../components/components.module';

@NgModule({
  declarations: [HomePage],
  imports: [
	  IonicPageModule.forChild(HomePage),
	  ComponentsModule
	],
})
export class HomePageModule { }

Then use the component like:

<frappe-charts [params]="chartParam"></frappe-charts>

That's it!


For more detailed instruction, view my blog post in Medium

Credits to frappe-charts for this awesome chart library!

frappe-charts-ionic-3's People

Contributors

ejfrias avatar elvis878 avatar

Watchers

 avatar

frappe-charts-ionic-3's Issues

chartWrapper is undefined?

I followed your instruction, but in the frappe-charts.ts I got that erro:

"Uncaught (in promise): TypeError: this.chartWrapper is undefined [..]"

What exactly the line " @ViewChild('chartWrapper') chartWrapper;" should do?

Thanks :)

Updating Values

It's me again :) I was able to generate the chart, but I'm not really sure how to update it. I saw that there is an update method in the library, but I'm not able to access it through my component.

It should be something similar to that?

this.chartCtrl.chart.update_values(...)

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.