【问题标题】:How to get series data on drag event in kendo UI如何在 kendo UI 中获取有关拖动事件的系列数据
【发布时间】:2015-09-16 23:58:07
【问题描述】:

在 Kendo UI 中,每当我们使用拖动事件时,我们都可以获得屏幕 x 和 y 位置,但如何在 Kendo UI 图表(折线图)中获取系列/数据源信息。

在下面的代码中,我使用拖动事件突出显示行字符(时间序列)中的一些信息,然后打印数据。

 function createChart(data) {

            $("#TimeSeriesPlot").kendoChart({

                title: {
                    text: series_name.toUpperCase()
                },
                dataSource :{
                    data:data.timeseries,
                },
                series: [{
                    type: "line",
                     field:"v",
                    categoryField:"ts",
               }],
                 valueAxis: {
                    labels: {
                        format: "{0}"
                    },title:{
                        text: "value"
                    },
                    line: {
                        visible: false
                    },

                 },
                categoryAxis: {
                 labels: {
                  type: "date",

                },  
               tooltip: {
                    visible: true,
                   // shared:true,
                     template: "${category} - ${value}"
                },

                /***events start from here***/

                plotAreaClick: onPlotAreaClick,
                seriesClick:onSeriesClick ,
                dragStart:onDragStart ,
                drag:onDrag,
                dragEnd:onDragEnd 

            });
        }
}

function onSeriesHover(e) {
        console.log(kendo.format("Series hover :: {0} ({1}): {2}",
            e.series.name, e.category, e.value));
        }


function onSeriesClick(e){
       //   console.log(selected_anamolies);
         //  console.log(e.category);
           selected_anamolies.push("ts",e.category);
           selected_anamolies.push("v",e.value);
}

function onDragStart(e){

       //  console.log("dragstart"+e.axisRanges.ts);

        //   console.log("dragstart"+e.sender._highlight._points[0].value);
       //     console.log("dragstart"+e.sender._highlight._points[0].category);


}

function onDrag(e){

        var Rect = kendo.geometry.Rect;
        var draw = kendo.drawing;
        prevloc=e.originalEvent.x.startLocation;
        currentloc=e.originalEvent.x.location;

        var rect=new Rect([prevloc,50],[currentloc-prevloc,150]);
        var path = draw.Path.fromRect(rect,{  stroke: null,fill:{color:"#d3f1fb",opacity:0.2}});
        var chart = e.sender;
//   var surface = draw.Surface.create($("#surface"));
        chart.surface.draw(path);
                    //                        
}


function onDragEnd(e){
  console.log(dragEnd)

}

【问题讨论】:

  • 请发布您的图表代码并解释您通过拖动实现的目标。
  • 请在问题中找到上面的代码
  • 那么,您是否尝试拖动一个矩形,然后获取该矩形内的所有点?
  • 是的,你是对的,目前我能够获得屏幕 x 和屏幕 y 点,但我想要数据绑定,所以我可以获得类别值但我不确定这怎么可能在拖动事件中。如果你能帮我解决这个问题,那就太好了。谢谢!

标签: kendo-ui kendo-datasource kendo-chart kendo-draggable


【解决方案1】:

为此,您需要从鼠标位置找到最平行的图表点。 然后,假设selectednode 是与鼠标当前位置最平行的点。 现在你可以在Dataitem变量Dataitem = selectednode._kendoNode.srcElement.chartElement.pointData.dataItem;中找到那个点的数据了

我已经为我解决了,就像..

$("#yourchartdivid").on('mousemove', function (el, ui) {
  var child = $(document).find('circle');
  var childrens = [];
child.filter(function (e, data) {
   if (data.attributes.stroke.value == trendcolor[es].color) {
   childrens.push(data);
   }
});
  getfrombottom(el.clientY, el, childrens, el, trendcolor[es].trendname, controlkey);});

现在定义新函数 getfrombottom()

function getfrombottom(bottom, event, childrens, i, trendname, controlkey) {
for (var o = bottom; o > 0; o--) {
    for (var k = 0; k < childrens.length ; k++) {
        var originalmousepossition = event.pageY;
        var originalmouseposition = event.pageX - 9;
        var circlestopposition = childrens[k].parentNode.getBoundingClientRect().top;
        var circleleftposition = childrens[k].cx.baseVal.value;
        if (originalmouseposition - circleleftposition < 3) {            

var selectednode = childrens[k];


        Dataitem = selectednode._kendoNode.srcElement.chartElement.pointData.dataItem;
        return false;
        }
    }
}}

如果它不适合你,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    相关资源
    最近更新 更多