Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新:使用Javascript/Jquery更改负预定值的颜色_Javascript_Jquery_Html_Css_D3.js - Fatal编程技术网

更新:使用Javascript/Jquery更改负预定值的颜色

更新:使用Javascript/Jquery更改负预定值的颜色,javascript,jquery,html,css,d3.js,Javascript,Jquery,Html,Css,D3.js,我正在工作的一个项目中,使用D3.js从CSV文件的表中获取值(一年中目录的毛利) 其思想是,当CSV文件中的数字发生更改时,html格式将在刷新时更改为新值。示例:今天我们赚了$xx.xx(在CSS中应该是绿色样式),但第二天我们赚了-$xx.xx(因为我们是负数,所以该值将是红色样式) 已更新: 这是一个新代码,用于更好地控制哪些表在负数或正数时会有文本颜色变化: $( document ).ready( function() { $( '#tableTwo tr' ).each(funct

我正在工作的一个项目中,使用D3.js从CSV文件的表中获取值(一年中目录的毛利)

其思想是,当CSV文件中的数字发生更改时,html格式将在刷新时更改为新值。示例:今天我们赚了$xx.xx(在CSS中应该是绿色样式),但第二天我们赚了-$xx.xx(因为我们是负数,所以该值将是红色样式)

已更新

这是一个新代码,用于更好地控制哪些表在负数或正数时会有文本颜色变化:

$( document ).ready( function() {
$( '#tableTwo tr' ).each(function() {
    $( this ).find( 'td' ).each(function() {
        //if cell value is less than 0, then change font color.
        console.log( $( this ).html() );
    });
});
});
如果为负值,则假定更改预定值,但未收到错误且未更改。此代码的脚本标记位于表标记的下方,因为d3.js也位于表标记的底部。因此,在d3.js中,函数调用html中的div以将数据表单也放置在csv中:

    <link rel="stylesheet" type="text/css" href="jean.css"/>
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
    <script src="http://d3js.org/d3.v3.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
    <div class="container">
            <div><h1 id = "headerFormat">Catalog 6F Matchback Report</h1> </div>

                <div id="firstCSV"></div>
                <div id="secondCSV"></div>
                <div id="thirdCSV"></div>
                <table id ="theSecretOne">
                    <thead>
                        <tr>
                            <th>Labor Cost Parameter</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Labor Cost</td>
                            <td>7%</td>
                        </tr>
                    </tbody>   

                </table>
                <div id ="fourthCSV"></div>
                <table id = "findMEPosition">
                    <tbody>
                        <tr>
                            <td>report revenue /cost corresponds to catalog allocated revenue/cost</td>
                        </tr>
                    </tbody>
                </table>
                <div id="fifthCSV"></div>
                <div id="sixthCSV"></div>
                <div id="seventhCSV"></div>
                <div id="miscPosition"></div>
            <!--<script>
                $(document).ready( function(){
                    $("td.of_number_be_evaluated:contains('-')").addClass('red');
                    $("td.of_number_be_evaluated:contains('+')").addClass('green');
                });
            </script>-->

    </div>
</body>
<script type='text/javascript' src="jean.js"></script> <!-- d3.js script to fill the table from the CSV file-->

<script type='text/javascript' src="numberColorChange.js"></script> <!-- color Change script-->
</html>

目录6F匹配报告
人工成本参数
人工成本
7%
报表收入/成本对应于目录分配的收入/成本
我已经意识到,在Chrome的检查页面上,在jQuery代码前面放置一个断点之后,D3.js在jQuery代码之后运行,这不会导致任何更改。是否有某种类型的函数可用于延迟jQuery脚本,以便D3.js可以将值放入要读取的表中


有人能帮我吗?如果需要更多的编码,我可以提供更多,因为我使用虚拟数据来查看这个项目需要多长时间。

因此,我意识到,在玩CSV文件数据时,当我想要更改为不同的值(货币、数字、小数等)时,EXCEL正在更改值以适应其结构。因此,我打开了升华文本上的CSV文件,查看值的实际格式

然后,我使用了来自


即使我把文字改成了崇高的文字,颜色也变化得非常好。感谢每一位为我指出正确方向的人。

为什么HTML中的jQuery代码会被注释?如果您可以共享jsfiddle演示,那也太好了。您是否尝试过用开发人员控制台调试它?正在调用document.ready()函数吗?找到美元('td')了吗?什么是cellValue.html()?是否有一个前导空格正在抛出你的子字符串?@ChrisG我已经更新了结果的主线程,它将回答你的问题question@Aziz我在那里放了一条评论,这样可以更容易地看到脚本为什么在那个区域。我为这个新的元素划去了旧的代码,因为它有助于未来的项目,我现在没有可用的JSFIDLE。有一个简单的解决方案,只使用D3:当创建元素时,根据值设置一个类,类似这样:
.attr(“class”,function(d){return(d<0)?“negative”:“positive”}
,并根据这些类设置CSS中的颜色。