【问题标题】:dojox chart highlight effect not workingdojox图表突出显示效果不起作用
【发布时间】:2012-10-16 14:49:03
【问题描述】:

我使用 dojo 1.8 版创建了一个简单的柱形图,我想为每一列添加鼠标悬停的高亮效果。

Dojo 的 dojox 图表 API 提供了一个很好的类,称为 Highlight,您应该能够实例化注入图表实例和绘图名称,如下所示...

new Highlight(ChartInstance, "plotName");

以下是支持这一点的文档:

http://dojotoolkit.org/reference-guide/1.8/dojox/charting.html#highlight

http://dojotoolkit.org/api/1.8/dojox/charting/action2d/Highlight

http://dojotoolkit.org/documentation/tutorials/1.8/charting/

现在我已经遵循了这个语法,但还没有让效果起作用,并且在 firebug 中没有报告任何脚本错误。这是我的测试页面...

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Test chart</title>

        <script>
            var dojoConfig = {
            baseUrl: "./",
            async: true,
            isDebug: true,
            parseOnLoad: true,
            gfxRenderer: "svg, canvas, silverlight",//svg is preferred chart renderer

            //here are the packages dojo will be aware of and related js files
            packages: [
                    //dojo specific packages
                    {name: "dojo", location: "libs/dojo"},
                    {name: "dojox", location: "libs/dojox"}
                ]
            };
    </script>

    </head>
    <body>

        <!-- create the chart div-->
        <div id="chartContent"></div>

        <!-- load dojo and provide config via header script -->
        <script src="libs/dojo/dojo.js"></script>

        <script>
            require(["dojo/parser", "dojo/domReady!"]);

            require([
                "dojox/charting/Chart",
              "dojox/charting/themes/Claro",
                "dojox/charting/plot2d/Columns",
                "dojox/charting/axis2d/Default",
                "dojox/charting/action2d/Highlight",
                "dojo/domReady!"
                ],
                function (Chart, Theme, ChartType, Default, Highlight){

                    chartData = [
                        { x: 1, y: 19021 },
                        { x: 2, y: 12837 },
                        { x: 3, y: 12378 },
                        { x: 4, y: 21882 },
                        { x: 5, y: 17654 },
                        { x: 6, y: 15833 },
                        { x: 7, y: 16122 }
                    ];

                    var chart = new Chart("chartContent", {title: "test bar chart"});

                    chart.setTheme(Theme);

                    chart.addPlot("barPlot", {type:ChartType, interpolate: false, tension: "S", markers: true, hAxis: "x", vAxis: "y"});

                    chart.addAxis("x", {title: "horizontal axis", titleOrientation: "away", min:0});
                    chart.addAxis("y", {title: "vertical axis", vertical: true});

                    chart.addSeries("bar series", chartData, {plot: "barPlot"});

                    new Highlight(chart, "barPlot");

                    chart.render();
                }
            );

        </script>
    </body>
</html>

要运行该页面,您需要调整 dojo 和 dojox 位置以匹配您自己的设置,您还可以通过在配置中为每个位置交换完整 URL 来指向它们的在线版本。

当您在浏览器中加载它时,您应该会看到一个柱形图,并注意到突出显示实例对每一列的鼠标悬停没有影响。

任何想法,也许我在这里错过了一些简单的东西?

【问题讨论】:

  • 我有同样的问题,高亮效果不适用于claro主题。

标签: javascript html dojo dojox.charting


【解决方案1】:

很久以后,但还是这样:

高光不适用于渐变作为填充。 我假设这是因为 Highlight 将检查使用的颜色,如果比 50% 更亮,则使用更亮的颜色...当主题包含渐变时,它会返回两个值并中断。

我在使用带有渐变的自定义主题时偶然发现了同样的问题,删除渐变并使用纯色解决了这个问题。

所以任何带有渐变的主题都不支持 Highlight。

【讨论】:

    【解决方案2】:

    好的,我现在发现了问题,说实话,这很烦人!

    这完全与 Claro 主题有关,我将其更改为其他主题之一,在这种情况下,我使用了 MiamiNice 主题,你相信吗,鼠标悬停现在可以工作了!!!

    有兴趣的可以打sn-p:

    require([
        "dojox/charting/Chart",
        "dojox/charting/themes/MiamiNice", <-- here it used to end /Claro
    

    我会把这个放到道场社区论坛上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 2019-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多