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

candlestick按照data:[{value: [1, 2, 3, 4]}]的形式画不出来 #6165

Closed
hayderGo opened this issue Jul 7, 2017 · 0 comments
Closed

candlestick按照data:[{value: [1, 2, 3, 4]}]的形式画不出来 #6165

hayderGo opened this issue Jul 7, 2017 · 0 comments

Comments

@hayderGo
Copy link

hayderGo commented Jul 7, 2017

One-line summary [问题简述]

因为需要给个别日期的K线item特别的样式高亮,查阅文档,尝试使用了data数组包每一项的value的方式书写option,但是出不了图,对照了很久,书写方式应该没错,请问一下问题出在哪里?谢谢!

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 3.6.2
  • Browser version [浏览器类型和版本]: chrome 58
  • OS Version [操作系统类型和版本]: win10

Expected behaviour [期望结果]

能够调整指定的K线块的样式

ECharts option [ECharts配置项]

var kDataRaw = [{"tradingDay":"2017-05-24","openPrice":7.16,"highPrice":7.16,"lowPrice":7.16,"closePrice":7.16,"dealQuantity":326800.00},{"tradingDay":"2017-05-25","openPrice":6.44,"highPrice":6.44,"lowPrice":6.44,"closePrice":6.44,"dealQuantity":700.00},{"tradingDay":"2017-05-26","openPrice":5.80,"highPrice":5.80,"lowPrice":5.80,"closePrice":5.80,"dealQuantity":300.00},{"tradingDay":"2017-05-31","openPrice":5.22,"highPrice":5.22,"lowPrice":5.22,"closePrice":5.22,"dealQuantity":100.00},{"tradingDay":"2017-06-01","openPrice":4.70,"highPrice":4.70,"lowPrice":4.70,"closePrice":4.70,"dealQuantity":1900.00},{"tradingDay":"2017-06-02","openPrice":4.23,"highPrice":4.23,"lowPrice":4.23,"closePrice":4.23,"dealQuantity":1100.00},{"tradingDay":"2017-06-05","openPrice":3.81,"highPrice":3.81,"lowPrice":3.81,"closePrice":3.81,"dealQuantity":11700.00},{"tradingDay":"2017-06-06","openPrice":3.43,"highPrice":3.43,"lowPrice":3.43,"closePrice":3.43,"dealQuantity":1300.00},{"tradingDay":"2017-06-07","openPrice":3.09,"highPrice":3.09,"lowPrice":3.09,"closePrice":3.09,"dealQuantity":9400.00},{"tradingDay":"2017-06-08","openPrice":2.78,"highPrice":2.78,"lowPrice":2.78,"closePrice":2.78,"dealQuantity":23100.00},{"tradingDay":"2017-06-09","openPrice":2.50,"highPrice":2.50,"lowPrice":2.50,"closePrice":2.50,"dealQuantity":75200.00},{"tradingDay":"2017-06-12","openPrice":2.25,"highPrice":2.25,"lowPrice":2.25,"closePrice":2.25,"dealQuantity":23000.00},{"tradingDay":"2017-06-13","openPrice":2.03,"highPrice":2.03,"lowPrice":2.03,"closePrice":2.03,"dealQuantity":102900.00},{"tradingDay":"2017-06-14","openPrice":1.83,"highPrice":1.83,"lowPrice":1.83,"closePrice":1.83,"dealQuantity":4495400.00},{"tradingDay":"2017-06-15","openPrice":1.65,"highPrice":1.65,"lowPrice":1.65,"closePrice":1.65,"dealQuantity":3693200.00},{"tradingDay":"2017-06-16","openPrice":1.49,"highPrice":1.49,"lowPrice":1.49,"closePrice":1.49,"dealQuantity":1429200.00},{"tradingDay":"2017-06-19","openPrice":1.34,"highPrice":1.34,"lowPrice":1.34,"closePrice":1.34,"dealQuantity":2015600.00},{"tradingDay":"2017-06-20","openPrice":1.21,"highPrice":1.40,"lowPrice":1.21,"closePrice":1.23,"dealQuantity":159744861.00},{"tradingDay":"2017-06-21","openPrice":1.23,"highPrice":1.33,"lowPrice":1.20,"closePrice":1.32,"dealQuantity":57823981.00},{"tradingDay":"2017-06-22","openPrice":1.35,"highPrice":1.44,"lowPrice":1.33,"closePrice":1.40,"dealQuantity":32884888.00},{"tradingDay":"2017-06-23","openPrice":1.39,"highPrice":1.40,"lowPrice":1.26,"closePrice":1.30,"dealQuantity":44728062.00},{"tradingDay":"2017-06-26","openPrice":1.32,"highPrice":1.37,"lowPrice":1.30,"closePrice":1.36,"dealQuantity":21436708.00},{"tradingDay":"2017-06-27","openPrice":1.35,"highPrice":1.42,"lowPrice":1.35,"closePrice":1.37,"dealQuantity":16695888.00},{"tradingDay":"2017-06-28","openPrice":1.37,"highPrice":1.44,"lowPrice":1.36,"closePrice":1.41,"dealQuantity":20647147.00},{"tradingDay":"2017-06-29","openPrice":1.42,"highPrice":1.52,"lowPrice":1.41,"closePrice":1.48,"dealQuantity":18923198.00},{"tradingDay":"2017-06-30","openPrice":1.48,"highPrice":1.53,"lowPrice":1.42,"closePrice":1.43,"dealQuantity":20756339.00},{"tradingDay":"2017-07-03","openPrice":1.44,"highPrice":1.48,"lowPrice":1.43,"closePrice":1.48,"dealQuantity":15941738.00},{"tradingDay":"2017-07-04","openPrice":1.49,"highPrice":1.52,"lowPrice":1.47,"closePrice":1.48,"dealQuantity":19426198.00},{"tradingDay":"2017-07-05","openPrice":1.50,"highPrice":1.63,"lowPrice":1.49,"closePrice":1.63,"dealQuantity":28769449.00},{"tradingDay":"2017-07-06","openPrice":1.67,"highPrice":1.77,"lowPrice":1.59,"closePrice":1.70,"dealQuantity":38804227.00}];
var kData = [];
var kDate = [];
 kDataRaw.map(item => {
            kDate.push(item.tradingDay);
            kData.push([
              item.openPrice,
              item.closePrice,
              item.lowPrice,
              item.highPrice
            ]);
          });
option = getOption(kData, kDate);
function getOption(kData, kDate) {
  var colors = {
    kNormal: '#234B65',
    kHighlight: '#F5A623',
    tag: 'rgba(56, 56, 56, 1)',
    splitLine: 'rgba(56, 56, 56, 0.5)',
    label: '#A6A6A6',
    progress: '#272727',
    progress_inner: '#393A3A'
  };
  //  营业部方框
  var rectPath = 'path://M-229.2,407.9l3,3h28.3c1.1,0,2,0.9,2,2v19.5c0,1.1-0.9,2-2,2H-261c-1.1,0-2-0.9-2-2v-19.5c0-1.1,0.9-2,2-2h29.3L-229.2,407.9z';
  // //  当天值标签
  // var tagPath = 'path://M-271.3,413.9v14l-7-5.5c-0.9-0.7-0.9-1.8,0-2.5L-271.3,413.9z M-271.3,413.9h26.5c1.1,0,2,0.9,2,2v10c0,1.1-0.9,2-2,2h-26.5V413.9z M-274,421.9c0.6,0,1-0.5,1-1c0-0.6-0.4-1-1-1c-0.6,0-1,0.5-1,1C-275,421.5-274.6,421.9-274,421.9z';
  
  var kData_real = kData.map(item => ({
    name: '日K',
    value: item,
    itemStyle: {
      color: colors.kNormal,
      color0: colors.kNormal,
      borderColor: colors.kNormal,
      borderColor0: colors.kNormal
    }
  }));
  console.log(kData_real);
  var option = {
    animation: false,
    grid: {
      left: 20,
      right: 45,
      top: '10%',
      bottom: 30
    },
    dataZoom: [
      {
        type: 'inside',
        show: true,
        // filterMode: 'empty',   // 不改变Y轴刻度, 并且平移超出的部分不显示(none会显示)
        zoomLock: true,       // 不改变X轴刻度
        xAxisIndex: 0,
        start: 50,
        end: 100
      },
      {
        type: 'slider',
        showDetail: false,
        backgroundColor: colors.progress,
        borderColor: colors.progress,
        fillerColor: colors.progress_inner,
        height: 6,
        handleSize: 0,
        bottom: 0,
        left: 0,
        right: 0,
        dataBackground: {
          lineStyle: {
            opacity: 0
          },
          areaStyle: {
            opacity: 0
          }
        }
      }
    ],
    xAxis: {
      gridIndex: 0,
      type: 'category',
      data: kDate,
      axisLine: { show: false },
      axisTick: {
        show: false,
        inside: true
      },
      axisLabel: {
        showMinLabel: true,
        showMaxLabel: true,
        formatter: (value) => {
          return value.substr(5);
        },
        textStyle: {
          fontSize: 12
        },
        interval: (index, value) => {
          if (index === 0 ||
            (index + 1) % (Math.ceil(kDate.length / 6)) === 0 ||
            index === kDate.length - 1) {
            return value;
          }
          return false;
        }
      }
    },
    yAxis: {
      gridIndex: 0,
      position: 'right',
      scale: true,
      splitNumber: 3,
      axisLine: { show: false },
      splitLine: {
        show: true,
        lineStyle: {
          color: colors.splitLine
        }
      },
      axisTick: { show: false }
    },
    textStyle: {
      color: colors.label
    },
    series: [
      {
        type: 'candlestick',
        name: '日K',
        // data: kData,
        data: kData_real,
        // itemStyle: {
        //   normal: {
        //     color: colors.kNormal,
        //     color0: colors.kNormal,
        //     borderColor: colors.kNormal,
        //     borderColor0: colors.kNormal
        //   }
        // },
      }
    ]
  };
  console.log(option);
  return option;
}

Other comments [其他信息]

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

1 participant