156Echarts - 平行坐标系(Parallel Nutrients)

简介: 156Echarts - 平行坐标系(Parallel Nutrients)
效果图

源代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="js/echarts.min.js"></script>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="dist/extension/dataTool.js"></script>
  </head>
  <body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="width: 1024px;height:768px;"></div>
    <script type="text/javascript">
      // 基于准备好的dom,初始化echarts实例
      var myChart = echarts.init(document.getElementById('main'));
      var option;
var indices = {
    name: 0,
    group: 1,
    id: 16
};
var schema = [
    {name: 'name', index: 0},
    {name: 'group', index: 1},
    {name: 'protein', index: 2},
    {name: 'calcium', index: 3},
    {name: 'sodium', index: 4},
    {name: 'fiber', index: 5},
    {name: 'vitaminc', index: 6},
    {name: 'potassium', index: 7},
    {name: 'carbohydrate', index: 8},
    {name: 'sugars', index: 9},
    {name: 'fat', index: 10},
    {name: 'water', index: 11},
    {name: 'calories', index: 12},
    {name: 'saturated', index: 13},
    {name: 'monounsat', index: 14},
    {name: 'polyunsat', index: 15},
    {name: 'id', index: 16}
];
var groupCategories = [];
var groupColors = [];
 $.get('data/nutrients.json', function (data) {
    normalizeData(data);
    myChart.setOption(option = getOption(data));
});
function normalizeData(originData) {
    var groupMap = {};
    originData.forEach(function (row) {
        var groupName = row[indices.group];
        if (!groupMap.hasOwnProperty(groupName)) {
            groupMap[groupName] = 1;
        }
    });
    originData.forEach(function (row) {
        row.forEach(function (item, index) {
            if (index !== indices.name
                && index !== indices.group
                && index !== indices.id
            ) {
                // Convert null to zero, as all of them under unit "g".
                row[index] = parseFloat(item) || 0;
            }
        });
    });
    for (var groupName in groupMap) {
        if (groupMap.hasOwnProperty(groupName)) {
            groupCategories.push(groupName);
        }
    }
    var hStep = Math.round(300 / (groupCategories.length - 1));
    for (var i = 0; i < groupCategories.length; i++) {
        groupColors.push(echarts.color.modifyHSL('#5A94DF', hStep * i));
    }
}
function getOption(data) {
    var lineStyle = {
        normal: {
            width: 0.5,
            opacity: 0.05
        }
    };
    return {
        backgroundColor: '#333',
        tooltip: {
            padding: 10,
            backgroundColor: '#222',
            borderColor: '#777',
            borderWidth: 1,
            formatter: function (obj) {
                var value = obj[0].value;
                return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">'
                    + schema[1].name + ':' + value[1] + '<br>'
                    + schema[2].name + ':' + value[2] + '<br>'
                    + schema[3].name + ':' + value[3] + '<br>'
                    + schema[4].name + ':' + value[4] + '<br>'
                    + schema[5].name + ':' + value[5] + '<br>'
                    + schema[6].name + ':' + value[6] + '<br>';
            }
        },
        title: [
            {
                text: 'Groups',
                top: 0,
                left: 0,
                textStyle: {
                    color: '#fff'
                }
            }
        ],
        visualMap: {
            show: true,
            type: 'piecewise',
            categories: groupCategories,
            dimension: indices.group,
            inRange: {
                color: groupColors //['#d94e5d','#eac736','#50a3ba']
            },
            outOfRange: {
                color: ['#ccc'] //['#d94e5d','#eac736','#50a3ba']
            },
            top: 20,
            textStyle: {
                color: '#fff'
            },
            realtime: false
        },
        parallelAxis: [
            {dim: 16, name: schema[16].name, scale: true, nameLocation: 'end'},
            {dim: 2, name: schema[2].name, nameLocation: 'end'},
            {dim: 4, name: schema[4].name, nameLocation: 'end'},
            {dim: 3, name: schema[3].name, nameLocation: 'end'},
            {dim: 5, name: schema[5].name, nameLocation: 'end'},
            {dim: 6, name: schema[6].name, nameLocation: 'end'},
            {dim: 7, name: schema[7].name, nameLocation: 'end'},
            {dim: 8, name: schema[8].name, nameLocation: 'end'},
            {dim: 9, name: schema[9].name, nameLocation: 'end'},
            {dim: 10, name: schema[10].name, nameLocation: 'end'},
            {dim: 11, name: schema[11].name, nameLocation: 'end'},
            {dim: 12, name: schema[12].name, nameLocation: 'end'},
            {dim: 13, name: schema[13].name, nameLocation: 'end'},
            {dim: 14, name: schema[14].name, nameLocation: 'end'},
            {dim: 15, name: schema[15].name, nameLocation: 'end'}
        ],
        parallel: {
            left: 280,
            top: 20,
            // top: 150,
            // height: 300,
            width: 400,
            layout: 'vertical',
            parallelAxisDefault: {
                type: 'value',
                name: 'nutrients',
                nameLocation: 'end',
                nameGap: 20,
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 14
                },
                axisLine: {
                    lineStyle: {
                        color: '#aaa'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#777'
                    }
                },
                splitLine: {
                    show: false
                },
                axisLabel: {
                    textStyle: {
                        color: '#fff'
                    }
                },
                realtime: false
            }
        },
        animation: false,
        series: [
            {
                name: 'nutrients',
                type: 'parallel',
                lineStyle: lineStyle,
                inactiveOpacity: 0,
                activeOpacity: 0.01,
                progressive: 500,
                smooth: true,
                data: data
            }
        ]
    };
}
      myChart.setOption(option);
    </script>
  </body>
</html>
目录
相关文章
154Echarts - 平行坐标系(Prices and Earnings 2012)
154Echarts - 平行坐标系(Prices and Earnings 2012)
38 0
81Echarts - 散点图(Scatter Nutrients Matrix)
81Echarts - 散点图(Scatter Nutrients Matrix)
44 0
81Echarts - 散点图(Scatter Nutrients Matrix)
158Echarts - 平行坐标系(Scatter Matrix)
158Echarts - 平行坐标系(Scatter Matrix)
29 0
157Echarts - 平行坐标系(Basic Parallel)
157Echarts - 平行坐标系(Basic Parallel)
36 0
155Echarts - 平行坐标系(Parallel Aqi)
155Echarts - 平行坐标系(Parallel Aqi)
87 0
80Echarts - 散点图(Scatter Nutrients)
80Echarts - 散点图(Scatter Nutrients)
38 0
|
17天前
|
小程序 前端开发 JavaScript
微信小程序图表制作利器:ECharts组件的使用与技巧
微信小程序图表制作利器:ECharts组件的使用与技巧
43 1
|
13天前
|
JavaScript
vue中使用echarts绘制双Y轴图表时,刻度没有对齐的两种解决方法
vue中使用echarts绘制双Y轴图表时,刻度没有对齐的两种解决方法
67 0
|
2月前
|
Web App开发 数据可视化 前端开发
Echart的使用初体验,Echarts的基本使用及语法格式,简单图表绘制和使用及图例添加【学习笔记】
本文介绍了ECharts的基本使用和语法格式,包括如何引入ECharts、创建容器、初始化echarts实例对象、配置option参数和一些基础图表的绘制方法。文章还提供了简单图表绘制和使用图例添加的示例代码,以及对ECharts特性和优势的概述。
Echart的使用初体验,Echarts的基本使用及语法格式,简单图表绘制和使用及图例添加【学习笔记】
|
3月前
|
小程序 JavaScript
微信小程序使用echarts图表(ec-canvas)
这篇文章介绍了在微信小程序中使用`ec-canvas`集成echarts图表的方法,包括解决加载时报错的问题、配置图表组件、以及在小程序页面中引入和使用这些图表组件的步骤。
403 1
微信小程序使用echarts图表(ec-canvas)