Giter Site home page Giter Site logo

ccchart's Introduction

This is a Simple and Realtime JavaScript chart library that does not depend on libraries such as jQuery or google APIs. You can use the following chart types. line, bar, pie, bezi, bezi2, stacked, area, stackedarea, stacked%, ampli, scatter, candle.

https://ccchart.com/index.htm

@see https://ccchart.com/ @see https://ccchart.com/test/ws2.htm @doc (old) https://ccchart.com/doc/ccchart-1.06.3.pdf @blog https://ngw.jp/~tato/wp/?tag=ccchart @chat https://cht.pw/chat.htm


License

MIT

Some of the download method

  • Download from this page: Download the zip file by clicking on the upper right [Download ZIP] button on this top page. And installing unzip. or etc...
  • or Download from ccchart.com
  • or Bower
    $ cd ./YourDir
    $ npm i -g bower
    $ bower i ccchart
    ccchart directory has been generated.
    YourDir/
      bower_components/
        ccchart/
            README.md
            ccchart-min.js
            ccchart.js
            update.json
            plugins/
  • etc...

    What's New

    I will make ccchart v2 later and make it public domain.

    Current Release: 2016/11/05 v1.12.084

    2016/11/1 Automatic extraction ccchart Reference

    2016/02/18 add heatmap Type
    Demo https://ccchart.com/#102
    Demo Realtime https://ccchart.com/test/heatmap/test1-hmp-v1.12.01-ws.htm
    #9
    @see https://ngw.jp/~tato/wp/?p=3737

    Demo heatmap Fit the image https://ccchart.com/test/heatmap/test1.htm


    2015/09/08 add Candle Type
    Demo ccchart.com: https://ccchart.com/#100 https://ccchart.com/test/candle/test-ws.htm

    Static Sample (Bar)

    Demo jsfiddle.net: https://jsfiddle.net/UkdvS/455/
    <script src="https://ccchart.com/js/ccchart.js" charset="utf-8"></script>
    <canvas id="hoge"></canvas>
    <script>
    var chartdata1 = {
      "config": {
        "title": "Bar Chart",
        "type": "bar"
      },
      "data": [
        ["Year",2007,2008,2009,2010,2011,2012,2013],
        ["Tea",435,332,524,688,774,825,999],
        ["Coffee",600,335,584,333,457,788,900],
        ["Juice",60,435,456,352,567,678,1260],
        ["Oolong",200,123,312,200,402,300,512]
      ]
    };
    ccchart.init('hoge', chartdata1)
    </script>
    
    Demo ccchart.com: https://ccchart.com/#57, https://ccchart.com/#72, https://ccchart.com/#73

    Static Sample (Line)

    Demo jsfiddle.net: https://jsfiddle.net/UkdvS/451/
    <script src="https://ccchart.com/js/ccchart.js" charset="utf-8"></script>
    <canvas id="hoge"></canvas>
    <script>
    var chartdata1 = {
      "config": {
        "title": "Option useMarker",
        "subTitle": "useMarker: maru",
        "type": "line",
        "useMarker": "maru",
        "lineWidth": 6,
        "markerWidth": 15
      },
      "data": [
        ["Year",2007,2008,2009,2010,2011,2012,2013],
        ["Tea",435,332,524,688,774,825,999],
        ["Coffee",600,335,584,333,457,788,900],
        ["Juice",60,435,456,352,567,678,1260],
        ["Oolong",200,123,312,200,402,300,512]
      ]
    };
    ccchart.init('hoge', chartdata1)
    </script>
    
    ccchart.com: https://ccchart.com/#15, https://ccchart.com/#7, https://ccchart.com/#96

    Other Types Samples


    Realtime Sample (use WebSocket)

    Demo ccchart.com: https://ccchart.com/#85
    Client Side
    <script src="https://ccchart.com/js/ccchart.js" charset="utf-8"></script>
    <canvas id="hoge"></canvas>
    <script>
    var chartdata1 = {
      "config": {
        "title": "WebSocket test",
        "subTitle": "realtime chart",
        "type": "bezi2",
        "lineWidth": 2,
        "minY": 0,
        "xScaleSkip": 3,
        "maxWsColLen": 18,
        "colorSet":
              ["#DDA0DD","#3CB000"]
      },
      "data": [
        ["time"],
        ["data1"],
        ["data2"]
      ]
    };
      ccchart
          .init('hoge', chartdata1)
          .ws('ws://ccchart.com:8016')
          .on('message', ccchart.wscase.oneColAtATime)
    </script>
    
    Server Side (Node.js)
    var WsServer = require('ws').Server;
    var tid;
    var ws = new WsServer({
        host: 'ccchart.com',
        port: 8016
    });
    broadCast();//start
    function broadCast() {
        tid = setInterval(function() {
            var dataAry = mkData();
            ws.clients.forEach(function(client) {
                if (client.readyState === 1)
                    client.send(JSON.stringify(dataAry));
            });
        }, 200);
    }
    function mkData() {
        var data = [
            ["Year"],
            ["s2"],
            ["s3"]
        ];
        var now = new Date();
        var H = now.getHours();
        var M = now.getMinutes();
        var S = now.getSeconds();
        H = (H < 10) ? '0' + H : H;
        M = (M < 10) ? '0' + M : M;
        S = (S < 10) ? '0' + S : S;
        data[0] = H + ':' + M + ':' + S;
        data[1] = Math.floor(Math.random(10) * 96);
        data[2] = 32 + Math.floor(Math.random(10) * 18);
        return data;
    }
    //on connection for Heartbeat これはハートビート用なのでいらなければ無くてもOK
    // ccchart はデフォルトでは60秒に一度"Heartbeat"という文字列を
    // サーバーへ送り、その返信である"Heartbeat"文字列を受信しています
    ws.on('connection', function(socket) {
        console.log(
            'conned: ' + ws.clients.length, (new Date),
            socket.upgradeReq.socket.remoteAddress
        );
        socket.on('message', function(msg) {
            var msg = JSON.stringify(msg);
            if (msg === 'Heartbeat') {
                if (socket.readyState === 1) {
                    socket.send(msg);
                    console.log(msg);
                }
            }
        });
    });
    

    ccchart.com: https://ccchart.com/#88, https://ccchart.com/#89, https://ccchart.com/#81


    Plugins

  • ccchart用プラグインの作り方 https://ngw.jp/~tato/wp/?p=389

  • Tips

    Codes

    type methods

    background methods

    axis methods

    scale methods

    title methods

    hanrei methods

    unit methods

    markers methods

    shadows methods

    flip methods

    websockets methods

    image methods

    memo methods

    transformation methods

    to be continued

    test3

    ccchart's People

    Contributors

    toshirot 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

    Watchers

     avatar  avatar  avatar  avatar  avatar

    ccchart's Issues

    fix about className of canvas

    The HTML className is ignored on the canvas element of ccchart-v1.11.01.js .
    Because it was incorrectly overwritten with setAttribute('class', '-ccchart').
    So , I was changed to "additionally write" after confirming the existence of a '-ccchart'.

    fixed on ccchart-v1.11.02.js
    http://ngw.jp/~tato/wp/?p=3698

    "minY:0 だと0が反映されない。数値タイプのconfig値処理を変更。

    データの最小値が優先されてる
    バグサンプル
    http://ccchart.org/test/minY/test-v1.12.06.htm

    thanx H.Iさん

    これは Number型の config値 の時にたとえば
    this.hoge = op.config.hoge || 10; などとしていると
    op.config.hoge === 0 だった時に 0に決まらずに10になってしまうという理由です。

    実は以前からこれを直そうと思っていたのですが、これを機会に メソッドを作って対応したいと思います
    作る関数
    ccchart.util.setConfigNum: function(it, propName, configVal, gfcVal, defaultVal)

    util:{
    
      setConfigNum: function(it, propName, configVal, gfcVal, defaultVal){
        //暫定
        //数値タイプのコンフィグ値をセットする configVal||gfcVal では0の時にうまく動作しないので
        //defaultValが無ければundefinedを返す
        //e.g. setConfigNum(this, 'minY', this.op.config.minY, this.gcf.minY, 0)
        it[propName+'Default'] = defaultVal;
        if(typeof configVal === 'number') return it[propName] = configVal;
        if(typeof gfcVal === 'number') return it[propName] = gfcVal;
        if(typeof defaultVal === 'number')return it[propName] = defaultVal;
        return undefined;
      }
    

    使用例(内部) 
    //最小値 デフォルトundefined
    this.minY = this.util.setConfigNum(this, 'minY', this.op.config.minY, this.gcf.minY)
    //線幅 デフォルト2
    this.lineWidth =
    this.util.setConfigNum(this, 'lineWidth', this.op.config.lineWidth, this.gcf.lineWidth, 2);

    WS受信したデータをccchartデータとして加工せずにそのまま代入するallColsAtATimeを標準機能に追加

    fujiichiさん
    自分でパターン関数をカスタマイズできるのですね。
    でも、allColsAtATimeとして標準機能にしていただけると、便利かもです。
    http://qiita.com/toshirot/items/a461cdc8c2079d9b8530#comment-2aff88c065aa677c54e5

    すみません。大変遅くなりました。
    v1.12.03でallColsAtATimeとして標準機能に追加します

    サンプル
    http://ccchart.org/test/someCols/test-2.htm#allColsAtATime

    サーバーからはこんなデータを送っています

    [
    ["日時","00:00","","","","01:00",""],
    ["製品A","1","4","12","10","0","5"],
    ["製品B","35","62","56","42","70","60"]
    ]

    Using releases/tags

    Hello,

    Greate work on this library, but bower has some problems installing it:

    bower                            retry Request to https://bower.herokuapp.com/packages/ccchart failed with ETIMEDOUT, retrying in 1.9s
    bower                            retry Request to https://bower.herokuapp.com/packages/ccchart failed with ETIMEDOUT, retrying in 3.1s
    bower ccchart#~1.11.06      not-cached git://github.com/toshirot/ccchart.git#~1.11.06
    bower ccchart#~1.11.06         resolve git://github.com/toshirot/ccchart.git#~1.11.06
    bower ccchart#~1.11.06    ENORESTARGET Tag/branch ~1.11.06 does not exist

    Can you please create a release/tag for the (new) versions released? That will solve the problems!

    Thank you

    I want to change to make a hanrei icons 凡例アイコンを変更したい

    I want to change to make a hanrei icons these are to be displayed automatically in conjunction. e.g. with the line of style (dash etc ..) and markers.
    Therefore, hanreiMarkerStyle will not be able to manually set.

    test sample for dash is here: http://ccchart.org/test/lineDash/test1.htm

    凡例アイコンを変更したい。たとえば、lineのマーカーやスタイル(ドットとかも)連動して自動的に表示されるみたいな。
    ただ、その結果hanreiMarkerStyle は手動設定できなくなるかも。
    ドットのテストサンプルはここ
    http://ccchart.org/test/lineDash/test1.htm

    積み上げチャートでのマイナス値を考慮してみる。& v1.12.03 - v1.12.05 でバーの起点位置が下がるバグ修正

    thanx t.kさん socketapi.com/user/wschat/1/wschat/chat.htm

    メモ:
    ・積み上げチャートでマイナスを考慮するとminYとmaxYの計算も別建てになる。
    ・drawStackedBar メソッドの that.ctx.translate あたりのアルゴリズムを変更する。
    ・-方向と+方向の判定と積み上げ高さの記録と巻き戻し
    ・列移動時のYリセット

    参考:
    基準線をy軸の真ん中に設定し、上方向プラス値、下方向マイナス値を表示する機能のバグ #22
    #22
    http://ccchart.org/test/barYMinus/test-2.htm

    リアルタイム+画像でちらつく Flickers in real time + image

    thanx 下り専門@kudarisenmonさん

    https://twitter.com/kudarisenmon/status/785976172924448768
    下り専門‏@kudarisenmon
    @toshirot ccchart使ってみました。公開ありがとうございます。高校物理の教材を作ってみました。 http://kudarisenmon.github.io/wave-simulator/
    スムーズに動いていい感じなのですが、「反射」を表現するためimgを使ってjpg背景画像で壁を作ったらかなりチラつきます

    リアルタイム+画像でちらつく問題を再現してみる
    http://jsfiddle.net/UkdvS/671/

    水平目盛り線AxisXを切りの良い値にする

    ちょっと考えてみる
    設定部分で関連しそうなのはこの辺。Pie type以外のY軸を使うチャートにはほぼすべて影響する。

           //水平目盛り線AxisXの本数
          if(typeof this.op.config.axisXLen === 'number'){
            this.axisXLen = this.op.config.axisXLen;
          } else {
            if(typeof this.gcf.axisXLen === 'number'){
              this.axisXLen = this.gcf.axisXLen;
            } else {
              this.axisXLen = 10; //default
    
              //Y目盛を小数点無しで (this.maxY - this.minY) < axisXLen なら
              //水平目盛り線の数を (this.maxY - this.minY +1)まで減らす
              if(this.yScaleDecimal === 'no'){
                if((this.maxY - this.minY) <  this.axisXLen) this.axisXLen = parseInt((this.maxY - this.minY));
              }
            }
          }
    
           //水平目盛線1本当たりのラベル値
          this.yGapValue = (this.maxY - this.minY) / (this.axisXLen);
    
          //値1当たりの高さ
          this.unitH = this.chartHeight / (this.maxY - this.minY);
    
          if(isFinite(this.unitH) === false){
            this.unitH = this.chartHeight;
            //0で割るとInfinityになってしまうのでY値の変化がない場合のように0ならchartHeightにしておく
          }
    
          if (this.type === 'stacked%') this.unitH = this.chartHeight / 100;
           //ラベルの値初期値
          this.wkYScale = this.minY;
    
          //for drawAxisX
          //水平目盛線用
          this.yGap = this.chartHeight / (this.axisXLen);
    
    
    
          var val = '', percent = '';
          if(this.type === 'stacked%'){
            val =Math.round( count * 100/this.axisXLen) +'%';
          } else {
            if(expression){this.wkYScale = this.maxY}//小手先修正あとで再考
            val = this.util.addComma(this, this.wkYScale, yScaleDecimal);
            percent = (this.yScalePercent==='yes')?( ' ('+ Math.round(count * 100/this.axisXLen)  +'%)' ):'';
          }
          this.wkYScaleStr = val + percent;//change type to string
    
    
    

    v1.12.06以降 type bar の barWithが効かない

    thanx leaf さん at Chat 4 ccchart auto ref http://ccchart.org/doc/refs/mkdoc.htm

    eaf> こんばんわ。「chartdata10」のコメントでは「bar」typeのグラフの幅「barWidth」が指定できそうなのですが、できませんでした。「stacked」typeでは指定できたのでなにか別の設定がいるのでしょうか? (2016/11/4 18:39:53)

    v1.12.05の修正でバグが混入したようです
    #25

    can you add heatmap chart ヒートマップ

    ras> 1) can you add heatmap chart (2016/1/27 23:1:53)
    toshirot> thanx ras. It is possible, but can not right now. because I am busy now --> "1) can you add heatmap chart" (2016/1/29 8:17:34)

    WebSocket: It initializes the number of times of re-connection 再接続:一度でも再接続に成功すれば再度リトライする回数を初期化

    http://ngw.jp/~tato/wp/?page_id=3501#comment-6513

    >鈴さん: 再接続の回数につきましては、8回の再接続が行われるとwsReCntが0になりその後は再接続を行わなくなるかと思うのですが、一度でも再接続に成功すれば再度リトライする回数を初期化できればよいなと思っておりました。

    ccchart.comについて

    ccchart.comって再開しないのでしょうか?
    ドキュメントだけでもいただくことはできないでしょうか?
    よろしくお願いいたします。

    基準線をy軸の真ん中に設定し、上方向プラス値、下方向マイナス値を表示する機能のバグ

    v1.08.8で追加した上記機能が v1.09からバグっていたようなのでv1.12.03で修正予定
    http://ngw.jp/~tato/wp/?p=1519#comment-210

    thanx > abcさん from chat ( http://socketapi.com/user/wschat/1/wschat/chat.htm )

    abc> こちらのコメント欄で、基準線をy軸の真ん中に設定し、上方向プラス値、下方向マイナス値を表示するといったチャートを作れるよう修正し、リリースしたとあるのですが、最新のccchartでは、値がマイナスでも上方向に棒グラフが伸びてしまいます。最新のccchartでは、y軸0を起点に、上下に伸びる棒グラフを作れないのでしょうか? (2016/6/15 10:40:12)

    Ver.1.12.07以降 "height" : "800","width" : "1260" で400px/600pxになってしまう。

    "height" : "800","width" : "1260" で指定すると400px/600pxになってしまう。
    thanx Petbottleさん。

    ver.1.12.07 #26 で追加したsetConfigNumメソッド内でNumber以外が与えられたケースを判定していないせいですね。
    したがって、
    "height" : "800","width" : "1260" ではなく
    "height" : 800,"width" : 1260 と書くと動作します。
    しかしこれでは今までと異なり使いにくいので、

    ccchart.util.setConfigNum() を下記のように修正しました。

      setConfigNum: function(it, propName, configVal, gfcVal, defaultVal){
        //暫定
        //数値タイプのコンフィグ値をセットする configVal||gfcVal では0の時にうまく動作しないので
        //defaultValが無ければundefinedを返す
        //e.g. setConfigNum(this, 'minY', this.op.config.minY, this.gcf.minY, 0)
        it[propName+'Default'] = defaultVal;
        if(typeof configVal === 'number') return it[propName] = configVal;
        if(typeof gfcVal === 'number') return it[propName] = gfcVal;
        if(typeof defaultVal === 'number')return it[propName] = defaultVal;
        return undefined;
      }
             ↓ 
             ↓ change
    
      setConfigNum: function(it, propName, configVal, gfcVal, defaultVal){
        //暫定
        //数値タイプのコンフィグ値をセットする configVal||gfcVal では0の時にうまく動作しないので
        //defaultValが無ければundefinedを返す
        //e.g. setConfigNum(this, 'minY', this.op.config.minY, this.gcf.minY, 0)
        configVal=_regex(configVal);
        gfcVal=_regex(gfcVal);
        defaultVal=_regex(defaultVal);
        it[propName+'Default'] = defaultVal;
        if(typeof configVal === 'number') return it[propName] = configVal;
        if(typeof gfcVal === 'number') return it[propName] = gfcVal;
        if(typeof defaultVal === 'number')return it[propName] = defaultVal;
        return undefined;
    
        function _regex(val){
          //一旦文字列化して数値以外の文字列除去後Number化して返す
          var _val=parseFloat((''+val).replace(/[^-{0,1}[0-9]\.]/g,''));
          if(isNaN(_val))_val='';//NaNは""{string}にする 
          return _val
        }
      }
    

    TEST===================
    _regex("80.6px")
    80.6
    _regex(80)
    80
    _regex(-80)
    -80
    _regex(+80)
    80
    _regex(80.12345)
    80.12345
    _regex(undefined)
    ""
    _regex("")
    ""
    _regex(".0")
    0
    _regex(".123")
    0.123
    _regex("-123")
    -123

    暫定
    http://ccchart.org/js/ccchart-v1.12.082b1.js

    ミスしてたので再修正しました。
    「//defaultValが無ければundefinedを返す」なので、、、

         ↓ change
      setConfigNum: function(it, propName, configVal, gfcVal, defaultVal){
        //暫定
        //数値タイプのコンフィグ値をセットする configVal||gfcVal では0の時にうまく動作しないので
        //defaultValが無ければundefinedを返す
        //e.g. setConfigNum(this, 'minY', this.op.config.minY, this.gcf.minY, 0)
        configVal=_regex(configVal);
        gfcVal=_regex(gfcVal);
        defaultVal=_regex(defaultVal);
        it[propName+'Default'] = defaultVal;
        if(typeof configVal === 'number') return it[propName] = configVal;
        if(typeof gfcVal === 'number') return it[propName] = gfcVal;
        if(typeof defaultVal === 'number')return it[propName] = defaultVal;
        return undefined;
    
        function _regex(val){
          //一旦文字列化して数値以外の文字列除去後Number化して返す
          var _val=parseFloat((''+val).replace(/[^-{0,1}[0-9]\.]/g,''));
          if(isNaN(_val))_val=undefined;//NaNはundefinedにする 
          return _val
        }
      }
    

    TEST===================
    _regex("80.6px")
    80.6
    _regex(80)
    80
    _regex(-80)
    -80
    _regex(+80)
    80
    _regex(80.12345)
    80.12345
    _regex(undefined)
    undefined //undefined
    _regex("")
    undefined //undefined
    _regex(".0")
    0
    _regex("0")
    0
    _regex(".123")
    0.123
    _regex("-123")
    -123

    暫定2 http://ccchart.org/js/ccchart-v1.12.082b2.js

    リリース
    2016/09/15 v1.12.082
    bug fixed. at ver.1.12.07 setConfigNum #30. thanx Petbottle

    memo メソッドに show/hidden をパラメータを付けたい

    更に、lineTo: [hoge, piyo] がデータに無い時は hidden にしたい。

    使用例:推移グラフなどで、数日後のメモをあらかじめ書いておいてその日が来たら自動的に表示させたい。過ぎた日のメモは自動で消したい。

    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.