Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WordCloud exits? Working example? #139

Closed
illsio opened this issue Mar 2, 2018 · 4 comments
Closed

WordCloud exits? Working example? #139

illsio opened this issue Mar 2, 2018 · 4 comments

Comments

@illsio
Copy link

illsio commented Mar 2, 2018

Hi,

I cant seem to get the wordcloud to work and i cant find any angular-highcharts example for it.
Error I am getting: 'The requested series type does not exist'
I implemented it with the example taken from the official site - worked for me on other occasions.
@http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/wordcloud/

import {Component, Input, NgZone, OnInit, SimpleChanges} from '@angular/core';
import {Chart} from 'angular-highcharts';

import * as highC from 'highcharts/js/highcharts.js';

@Component({
  selector: 'app-word-cloud',
  templateUrl: './word-cloud.component.html',
  styleUrls: ['./word-cloud.component.less']
})
export class WordCloudComponent implements OnInit {


  @Input() chartTitle = "";
  text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean bibendum erat ac justo sollicitudin, quis lacinia ligula fringilla. Pellentesque hendrerit, nisi vitae posuere condimentum, lectus urna accumsan libero, rutrum commodo mi lacus pretium erat. Phasellus pretium ultrices mi sed semper. Praesent ut tristique magna. Donec nisl tellus, sagittis ut tempus sit amet, consectetur eget erat. Sed ornare gravida lacinia. Curabitur iaculis metus purus, eget pretium est laoreet ut. Quisque tristique augue ac eros malesuada, vitae facilisis mauris sollicitudin. Mauris ac molestie nulla, vitae facilisis quam. Curabitur placerat ornare sem, in mattis purus posuere eget. Praesent non condimentum odio. Nunc aliquet, odio nec auctor congue, sapien justo dictum massa, nec fermentum massa sapien non tellus. Praesent luctus eros et nunc pretium hendrerit. In consequat et eros nec interdum. Ut neque dui, maximus id elit ac, consequat pretium tellus. Nullam vel accumsan lorem.";

  public wordCloudChart;

  constructor(private zone: NgZone) {
  }

  ngOnInit() {
    this.wordCloudChart = this.getWordCloudChart(this.text);
  }

  private getWordCloudChart(text) {
    let seriesData = this.createDataFromText(text);

    return new Chart({
      chart: {
        width: 600,
        height: 400
      },
      series: [{
        type: 'wordcloud',
        data: seriesData,
        name: 'Occurrences'
      }],
      title: {
        text: this.chartTitle
      }
    });
  }

  private createDataFromText(text: string) {
    let lines = text.split(/[,\. ]+/g);
    let realLines = [];
    for (let line of lines) {
      if (line && line.length > 3) {
        realLines.push(line);
      }
    }
    let data = highC.reduce(realLines, function (arr, word) {
      let obj = highC.find(arr, function (object) {
        return object.name === word;
      });
      if (obj) {
        obj.weight += 1;
      } else {
        obj = {
          name: word,
          weight: 1
        };
        arr.push(obj);
      }
      return arr;
    }, []);
    return data;
  }
}
@cebor
Copy link
Owner

cebor commented Mar 2, 2018

@illsio Hi, you have to import and load the wordcloud module, as described here: https://github.com/cebor/angular-highcharts#using-highcharts-modules

@cebor
Copy link
Owner

cebor commented Mar 2, 2018

reopen if this does not solve your issue.

@cebor cebor closed this as completed Mar 2, 2018
@illsio
Copy link
Author

illsio commented Mar 5, 2018

Hey, thanks for your reply.
I tried that already ....
Wordcloud stays as above, changes made like below:

app.modules.ts

import {ChartModule, HIGHCHARTS_MODULES} from 'angular-highcharts';
import more from 'highcharts/highcharts-more.src';
import exporting from 'highcharts/modules/exporting.src';
import wordcloud from 'highcharts/modules/wordcloud.src';

export function highchartsModules() {
  // apply Highcharts Modules to this array
  return [ more, exporting, wordcloud];
}
   
{provide: HIGHCHARTS_MODULES, useFactory: highchartsModules },

This results in:
TypeError: chartModule is not a function

@illsio
Copy link
Author

illsio commented Mar 5, 2018

Found:
#112

Made the following changes:

import * as more from 'highcharts/highcharts-more.src';
import * as exporting from 'highcharts/modules/exporting.src';
import * as wordcloud from 'highcharts/modules/wordcloud.src';

Changed this (although unclear if that is necessary):
"angular/cli": "1.6.5"
to
"angular/cli": "^1.7.2",

Miraculously also the export-function started working =)

SWEET
CHEERS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants