D3 二维图表的绘制系列(七)堆叠面积图

D3 二维图表的绘制系列(四)堆叠柱状图 上一篇: 多列柱状图 https://blog.youkuaiyun.com/zjw_python/article/details/98205614 下一篇: 横向柱状图 https://blog.youkuaiyun.com/zjw_python/article/details/98201470 代码结构和初始化画布的Chart对象介绍,请先看 https://blog.youkuaiyun.com/zjw_python/arti... 阅读详情

上一篇: 基础折线图 https://blog.youkuaiyun.com/zjw_python/article/details/98210977

下一篇: 曲线图 https://blog.youkuaiyun.com/zjw_python/article/details/98478578

代码结构和初始化画布的Chart对象介绍,请先看 https://blog.youkuaiyun.com/zjw_python/article/details/98182540

本图完整的源码地址: https://github.com/zjw666/D3_demo/tree/master/src/lineChart/stackedAreaChart

1 图表效果

在这里插入图片描述

2 数据

date,total,food,transportation,education
Mon,120,30,40,50
Tue,200,20,80,100
Wed,150,20,50,80
Thu,80,10,30,40
Fri,70,15,20,35
Sat,110,10,30,70
Sun,130,20,50,60

3 关键代码

导入数据

d3.csv('./data.csv', function(d){
   
   
    return {
   
   
        date: d.date,
        total: +d.total,
        food: +d.food,
        transportation: +d.transportation,
        education: +d.education
    };
}).then(function(data){
   
   
.....

一些样式参数配置,与基础折线图类似

const config = {
   
   
        margins: {
   
   top: 80, left: 80, bottom: 50, right: 80},
        textColor: 'black',
        gridColor: 'gray',
        ShowGridX: [],
        ShowGridY: [50, 100, 150, 200, 250, 300, 350, 400],
        title: '堆叠面积图',
        pointSize: 5,
        pointColor: 'white',
        hoverColor: 'red',
        animateDuration: 1000
    }

尺度转换和布局函数定义,堆叠面积图和堆叠柱状图类似,都使用了d3.stack计算布局

/* ----------------------------尺度转换------------------------  */
    chart.scaleX = d3.scalePoint()
                    .domain(data.map((d) => d.date))
                    .range([0, chart.getBodyWidth()])
    
    chart.scaleY = d3.scaleLinear()
                    .domain([0, (Math.floor((d3.max(data, (d) => d.total) + d3.max(data, (d) => d.food) + d3.max(data, (d) => d.education) + d3.max(data, (d) => d.transportation))/10) + 1)*10])
                    .range([chart.getBodyHeight(), 0])

    chart.stack = d3.stack()
                    .keys(['total', 'food', 'transportation', 'education'])
                    .order(d3.stackOrderAscending)
                    .offset(d3.stackOffsetNone);

渲染线条,这里与基础折线图类似,使用插值和中间帧实现动画过渡效果

/* ----------------------------渲染线条------------------------  */
    chart.renderLines = function(){
   
   

        let lines = chart.body().selectAll('.line')
                    .data(chart.stack(data));

            lines.enter()
                    .append('path')
                    .attr('class', (d) => 'line line-' + d.key)
                .merge(lines)
                    .attr('fill', 'none')
                    .attr('stroke', (d,i) => chart._colors(i))
                    .transition().duration(config.animateDuration)
                    .attrTween('d', lineTween);
            
            lines.exit()
                    .remove
D3 二维图表的绘制系列(一)介绍 1 介绍 D3 (或者叫 D3.js )是一个基于 web 标准的 JavaScript 可视化库. D3 可以借助 SVG, Canvas 以及HTML 将你的数据生动的展现出来. D3 结合了强大的可视化交互技术以及数据驱动 DOM 的技术,让你可以借助于现代浏览器的强大功能自由的对数据进行可视化 学习了d3一个多月,通过绘制一些简单的二维图表,总算入门了d3。强烈推荐《D3数据可视化实战... 阅读详情

相关推荐

D3 二维图表的绘制系列(二十)河流图

上一篇: 封闭图 https://blog.youkuaiyun.com/zjw_python/article/details/98492510 下一篇: 仪表盘图 https://blog.youkuaiyun.com/zjw_python/article/details/98201470 代码结构和初始化画布的Chart对象介绍,请先看 https://blog.youkuaiyun.com/zjw_python/article...

zjw_python的博客 5869

数据可视化工具汇总

Three.js是一个基于WebGL的JavaScript库,它简化了在Web浏览器中创建和展示三维图形的过程。Three.js拥有活跃的社区和众多的第三方插件,如GLTFLoader、OrbitControls等,提供了丰富的功能和扩展性。VTK是一款免费开放的软件工具,用于3D图形、建模、图像处理、科学数据可视化和其他信息可视化。

duansamve的博客 1333

MATLAB绘图全攻略:19种方法覆盖数学建模与科研可视化

数据可视化是科学计算与工程分析的核心环节,其本质是将抽象数据转化为直观图形,揭示数据内在规律。从原理层面,可视化基于人类视觉认知特性,通过坐标映射、颜色编码和图形元素组合,实现多维信息的降维呈现。在技术价值上,优秀的图表不仅能提升结果说服力,更是发现数据异常、验证模型合理性的关键工具,广泛应用于算法调试、结果对比和趋势分析等场景。本文聚焦MATLAB这一工程计算平台,深入解析其强大的绘图功能,涵盖从基础二维图形到三维曲面、统计图表及动态可视化等19种核心方法,并结合数学建模与科研实践中的热词如“数据呈现”和

weixin_33888907的博客 440

2024年Web前端最新d3实现曲线面积图,柱状图,天气曲线 案例(1),金三银四Web前端面试的一些感受

由于篇幅限制,pdf文档的详解资料太全面,细节内容实在太多啦,所以只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】top: 30size: 14,top: 20top: 30r: 4,width: 20,/**创建实例, 去使用封装好的方法**/mydrow.drowLine() //直接绘制曲线mydrow.drowarea() //增加面积图。

2401_84435700的博客 476

html显示堆叠面积图和堆叠图

html实现堆叠面积图和堆叠图,以及两张图合一显示在同一界面

二维数据或者图片堆叠形成三维空间的表示.zip_matlab_matlab 图像处理_matlab在一个坐标系画不同三维图_ma

matlab在一个坐标系内让二维图片堆叠形成三维空间的表示 二维数据或者图片堆叠在三维空间的表示,图片堆叠方便查看 类似origin里面的瀑布图的方法,只是这是在matlab里面实现。 matlab多张图片同时在三维空间中显示,沿着某一个坐标轴 matlab在一个坐标系画不同三维图综合整理,包含了几种画这种堆叠图的介绍的资源,也属于综合整理,感谢各位原作者的贡献。 为了挣点小积分实属不易,望理解,大家可以到TB花一毛五就能帮下载,感谢支持。 码字不易,感谢支持。 也可以去知乎或者优快云看我写的介绍,链接如下: 知乎:https://zhuanlan.zhihu.com/p/438782250 csdn:https://blog.youkuaiyun.com/wmying033/article/details/121625608?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164134593916780274112816%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164134593916780274112816&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-1-121625608.pc_search_result_cache&utm_term=matlab%E5%9C%A8%E4%B8%80%E4%B8%AA%E5%9D%90%E6%A0%87%E7%B3%BB%E5%86%85%E8%AE%A9%E4%BA%8C%E7%BB%B4%E5%9B%BE%E7%89%87%E5%A0%86%E5%8F%A0%E5%BD%A2%E6%88%90%E4%B8%89%E7%BB%B4%E7%A9%BA%E9%97%B4%E7%9A%84%E8%A1%A8%E7%A4%BA&spm=1018.2226.3001.4187

配电变压器测控终端装置设计

配电变压器测控终端装置在电网运行中承担着数据采集、状态监测、故障预警及远程控制的关键任务,其性能直接关系到配电系统的安全性与可靠性。本研究围绕测控终端的硬件电路、软件算法、通信系统及系统优化展开深入分析,并基于实验测试验证系统性能。硬件设计包括模拟量输入电路、电压电流信号变换电路、A/D转换电路、控制与通信电路及系统电源电路,确保信号采集的高精度与系统的稳定性。软件部分涵盖系统控制程序、数据采集与处理程序、通信程序及显示与控制程序,实现数据的实时处理与传输。通信模块结合RS-485、CAN总线及以太网技术,

weixin_44553616的博客 1103

Anomalib实战指南:从零开始构建自定义异常检测数据集

本文提供了一份详细的Anomalib实战指南,指导用户从零开始构建自定义异常检测数据集。文章深入解析了数据准备的核心步骤、目录结构规范,并对比了PatchCore与FastFlow等关键模型的适用场景。通过清晰的代码示例,手把手演示了环境配置、模型训练与推理评估的全流程,旨在帮助开发者快速掌握这一工业视觉异常检测利器,有效解决实际生产中的缺陷识别难题。

weixin_29054245的博客 643

别再只盯着版图画了!聊聊CMOS工艺里那个‘看不见的手’:STI应力(LOD效应)对模拟电路的实际影响

本文深入探讨了CMOS工艺中STI应力(LOD效应)对模拟电路设计的实际影响,揭示了这一隐形变量如何导致电流镜匹配偏差等常见问题。通过分析应力产生的物理机制、空间分布特性,以及提供伪器件设计、版图布局优化等实用解决方案,帮助工程师有效管理STI应力效应,提升电路性能。文章还探讨了FinFET工艺下的新挑战及机器学习在应力优化中的应用前景。

weixin_42656416的博客 359

S32K144之芯片锁死解锁——进入HardFault

S32K144之芯片锁死解锁——进入HardFault 最近遇到因为软件代码问题导致进入HardFault,从而使芯片锁死,来简述具体现象以及最终的解锁方法。 导致原因:如下图,在进行Gpio的相关配置,case后面没有break语句,导致芯片进入HardFault。 现象1:reset引脚持续为低,reset指示灯常亮。如果掉电后重新上电,通过示波器抓取reset引脚的波形,会有510us左右或者29ms左右的低电平脉冲出现,一般会出现两三次左右并且没有规矩,持续几秒的高电平之后,reset脚再次被拉低

weixin_41935674的博客 8275

ShardingSphere 5.3 系列Spring 配置升级指南 | Spring Cloud 47

在 `5.3.0` 版本以前,`ShardingSphere-JDBC` 同时支持 `Java API`、`YAML`、`Spring Boot Starter` 和 `Spring Namespace` 等配置方式。 - 当新增或更新 API 时,需要调整多项配置文件,工作量大 - 社区需要维护多重配置文档和示例 - `Spring Bean` 生命周期管理容易受到项目其他依赖的影响,比如 `PostProcessor` 无法正常执行 - `Spring Boot Starter` 和 `Spring N

gmHappy 2万+

12、每日卫星任务规划问题的不同公式

本文探讨了卫星任务规划问题的多种数学公式表示方法,包括传统的整数线性规划(ILP)模型、改进的基于路径的公式、基于集合覆盖的公式以及动态规划公式。通过案例研究比较了不同公式的求解效率和适用场景,并提供了使用Python进行实际求解的操作步骤。最后讨论了进一步优化策略及未来研究方向,旨在为解决卫星任务规划问题提供全面的理论支持和实践指导。

assembly8low的博客 203

专栏二十:如何选择你的单细胞亚群的分辨率--ROGUE

ROGUE这是继chooseR后第二个计算单细胞亚群分辨率的内容,其实关于代码的运行很简单,网上已经有不少教程,重复这些就没意思了,这里主要是结合探讨一下这个算法。

m0_58549466的博客 981

使用STM32H7点亮RGB屏幕

希望本文能对你有所帮助!RGB屏幕是一种具有红、绿、蓝三种颜色通道的显示设备,通过控制每个通道的亮度,可以显示出丰富多彩的图像和动画。要使用STM32H7控制RGB屏幕,我们需要连接适当的引脚,并编写适当的代码来控制每个颜色通道的亮度。在主循环中,我们先点亮红色通道,然后延迟一段时间,接着点亮绿色通道,再延迟一段时间,最后点亮蓝色通道,并再次延迟。需要注意的是,示例代码中的延迟循环使用了一个简单的计数器实现,但实际应用中可能需要更精确的延迟方式,例如使用定时器中断或操作系统提供的延迟函数。

QoyOle的博客 924

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

上一篇: D3 二维图表的绘制系列(六)基础折线图
下一篇: D3 二维图表的绘制系列(八)曲线图
PAT-python-zjw
博客等级 码龄10年 381粉丝 408原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值