Multiple Values on x Axes With C3JS ( Timeseries )

こ雲淡風輕ζ 提交于 2019-12-12 00:46:43

问题


I have this nice graph :

I also have this array for the blue part ( Area-Spline ).

["x2", "2015-01-05 00:00:00", "2015-01-12 00:00:00", "2015-01-19 00:00:00", "2015-01-26 00:00:00", "2015-02-02 00:00:00", "2015-02-09 00:00:00", "2015-02-16 00:00:00", "2015-02-23 00:00:00", "2015-03-02 00:00:00", "2015-03-09 00:00:00", "2015-03-16 00:00:00", "2015-03-23 00:00:00", "2015-03-30 00:00:00", "2015-04-06 00:00:00", "2015-04-13 00:00:00", "2015-04-20 00:00:00", "2015-04-27 00:00:00", "2015-05-04 00:00:00", "2015-05-11 00:00:00", "2015-05-18 00:00:00", "2015-05-25 00:00:00", "2015-06-01 00:00:00", "2015-06-08 00:00:00", "2015-06-15 00:00:00", "2015-06-22 00:00:00", "2015-06-29 00:00:00", "2015-07-06 00:00:00", "2015-07-13 00:00:00", "2015-07-20 00:00:00", "2015-07-27 00:00:00", "2015-08-03 00:00:00", "2015-08-10 00:00:00", "2015-08-17 00:00:00", "2015-08-24 00:00:00", "2015-08-31 00:00:00", "2015-09-07 00:00:00", "2015-09-14 00:00:00", "2015-09-21 00:00:00", "2015-09-28 00:00:00", "2015-10-05 00:00:00", "2015-10-12 00:00:00", "2015-10-19 00:00:00", "2015-10-26 00:00:00", "2015-11-02 00:00:00", "2015-11-09 00:00:00", "2015-11-16 00:00:00", "2015-11-23 00:00:00", "2015-11-30 00:00:00", "2015-12-07 00:00:00", "2015-12-14 00:00:00", "2015-12-21 00:00:00", "2015-12-28 00:00:00", "2016-01-04 00:00:00", "2016-01-11 00:00:00", "2016-01-18 00:00:00", "2016-01-25 00:00:00", "2016-02-01 00:00:00"]

The circles on the graph have this date value :

["x1", "2013-12-30 00:00:00", "2014-01-06 00:00:00", "2014-01-13 00:00:00", "2014-01-20 00:00:00", "2014-01-27 00:00:00", "2014-02-03 00:00:00", "2014-02-10 00:00:00", "2014-02-17 00:00:00", "2014-02-24 00:00:00", "2014-03-03 00:00:00", "2014-03-10 00:00:00", "2014-03-17 00:00:00", "2014-03-24 00:00:00", "2014-03-31 00:00:00", "2014-04-07 00:00:00", "2014-04-14 00:00:00", "2014-04-21 00:00:00", "2014-04-28 00:00:00", "2014-05-05 00:00:00", "2014-05-12 00:00:00", "2014-05-19 00:00:00", "2014-05-26 00:00:00", "2014-06-02 00:00:00", "2014-06-09 00:00:00", "2014-06-16 00:00:00", "2014-06-23 00:00:00", "2014-06-30 00:00:00", "2014-07-07 00:00:00", "2014-07-14 00:00:00", "2014-07-21 00:00:00", "2014-07-28 00:00:00", "2014-08-04 00:00:00", "2014-08-11 00:00:00", "2014-08-18 00:00:00", "2014-08-25 00:00:00", "2014-09-01 00:00:00", "2014-09-08 00:00:00", "2014-09-15 00:00:00", "2014-09-22 00:00:00", "2014-09-29 00:00:00", "2014-10-06 00:00:00", "2014-10-13 00:00:00", "2014-10-20 00:00:00", "2014-10-27 00:00:00", "2014-11-03 00:00:00", "2014-11-10 00:00:00", "2014-11-17 00:00:00", "2014-11-24 00:00:00", "2014-12-01 00:00:00", "2014-12-08 00:00:00", "2014-12-15 00:00:00", "2014-12-22 00:00:00", "2014-12-29 00:00:00", "2015-01-05 00:00:00", "2015-01-12 00:00:00", "2015-01-19 00:00:00", "2015-01-26 00:00:00", "2015-02-02 00:00:00", "2015-02-09 00:00:00", "2015-02-16 00:00:00", "2015-02-23 00:00:00", "2015-03-02 00:00:00", "2015-03-09 00:00:00", "2015-03-16 00:00:00", "2015-03-23 00:00:00", "2015-03-30 00:00:00", "2015-04-06 00:00:00", "2015-04-13 00:00:00", "2015-04-20 00:00:00", "2015-04-27 00:00:00", "2015-05-04 00:00:00", "2015-05-11 00:00:00", "2015-05-18 00:00:00", "2015-05-25 00:00:00", "2015-06-01 00:00:00", "2015-06-08 00:00:00", "2015-06-15 00:00:00", "2015-06-22 00:00:00", "2015-06-29 00:00:00", "2015-07-06 00:00:00", "2015-07-13 00:00:00", "2015-07-20 00:00:00", "2015-07-27 00:00:00", "2015-08-03 00:00:00", "2015-08-10 00:00:00", "2015-08-17 00:00:00", "2015-08-24 00:00:00", "2015-08-31 00:00:00", "2015-09-07 00:00:00", "2015-09-14 00:00:00", "2015-09-21 00:00:00", "2015-09-28 00:00:00", "2015-10-05 00:00:00", "2015-10-12 00:00:00", "2015-10-19 00:00:00", "2015-10-26 00:00:00", "2015-11-02 00:00:00", "2015-11-09 00:00:00", "2015-11-16 00:00:00"…]

This is the the x axes what is shown on the graph.

As you can see i have multiple values for the x axes ( 2 different date array ).

The first one starts at 2013-12-03 but the second one, as shown above starts at 2015.

How can i draw the second array to start at 2015 instead instead of 2013?

Graph Code :

  chart = c3.generate({
      point: {
        r: function (d) {
          if (d.id == 'A. v. Hensbergen') {
            d.parkeerduur = parking_duur_hensbergen[d.index];
            return d.parkeerduur;
          }

          if (d.id == 'Gemeentehuis') {
            d.parkeerduur = parking_duur_gemeentehuis[d.index];
            return d.parkeerduur;
          }

          if (d.id == 'Tricotage') {
            d.parkeerduur = parking_duur_tricotage[d.index];
            return d.parkeerduur;
          }


          if (d.id == 'Coornhertpad') {
            d.parkeerduur = parking_duur_coornhertpad[d.index];
            return d.parkeerduur;
          }

          if (d.id == 'Duivenweide') {
            d.parkeerduur = parking_duur_duivenweide[d.index];
            return d.parkeerduur;
          } else {
            return 3;
          }
        }
      },
      xs: {
        'data1': 'x1',
        'passanten': 'x2'
      },
      bindto: '#chatterplot_elastic',
      data: {
        colors: {
          passanten: '#007bb0'
        },
        x: 'x1',
        // @todo should be different based on interval selector.
        xFormat: '%Y-%m-%d %H:%M:%S',
        columns: [
          getParkingDates(),
          PassantenData,
          PassantenDatesData,
          PassantenData,
          HensbergenData,
          GemeentehuisData,
          CoornhertpadData,
          DuivenweideData,
          TricotageData
        ],
        axes: {
          'passanten': 'y',
          'time_period': "x",
          'A. v. Hensbergen': 'y2',
          'Gemeentehuis': 'y2',
          'Coornhertpad': 'y2',
          'Duivenweide': 'y2',
          'Tricotage': 'y2'
        },
        types: {
          passanten: 'area-spline',
          'A. v. Hensbergen': 'scatter',
          'Gemeentehuis': 'scatter',
          'Coornhertpad': 'scatter',
          'Duivenweide': 'scatter',
          'Tricotage': 'scatter'
        },
        onclick: function (e) {
          updateGraphMapper(e);
        }
      },
      axis: {
        y: {
          label: {
            text: 'Passanten',
            position: 'outer-middle'
          }
        },
        y2: {
          show: true,
          min: 0,
          max: 100,
          padding: {top: 0, bottom: 0},
          label: {
            text: 'Bezettingsgraad %',
            position: 'outer-middle'
          }
        },
        x: {
          type: 'timeseries',
          localtime: true,
          tick: {
            format: formatX,
            rotate: 75,
            multiline: false,
            culling: {
              max: 60,
            },
          },
        },
      },
    });
  }

回答1:


Remove this string x: 'x1', After you must set xs param for each line name like this:

xs: {
    'data1': 'x1',
    'passanten': 'x2',
    'A. v. Hensbergen': 'x1', // or 'x2'
    'Gemeentehuis': 'x1', // or 'x2'
    ......
    'OTHER COLUMN': 'x2', // or 'x1'
  },

Try this example to see your problem: https://jsfiddle.net/xsLgbhwt/



来源:https://stackoverflow.com/questions/36770220/multiple-values-on-x-axes-with-c3js-timeseries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!