arrow of line chart highcharts

后端 未结 2 651
长情又很酷
长情又很酷 2020-12-22 06:39

I need to draw arrow of my line chart but i don\'t know well, here there are my code that make arrow http://jsfiddle.net/VQyVs/ I have probleme with serie 2

         


        
相关标签:
2条回答
  • 2020-12-22 07:21

    Series 2 is not sorted properly. It's putting the arrow head on the last point in the array which happens to be the first point on the X axis.

       {
         data: [[0.10391336,-0.647706317],
            [0.208684058,-0.439022259],
        [0.031920245,-0.407102014],
        [-0.280249839,-0.687351853]].sort(), // I added the .sort...
     marker: {
            enabled: false
         }
       }
    

    UPDATE

    I think I understand what you are after now. To reverse the direction of the head, you'll have to test for the direction (is it moving to the left or right) and then modify how it's drawn:

        if (lastPoint.plotX > nextLastPoint.plotX)
        {
            // to the right
            path.push(
                'L',
                lastPoint.plotX + arrowWidth * Math.cos(angle),
                lastPoint.plotY - arrowWidth * Math.sin(angle)
            );
            path.push(
                lastPoint.plotX + arrowLength * Math.sin(angle),
                lastPoint.plotY + arrowLength * Math.cos(angle)
            );
            path.push(
                lastPoint.plotX - arrowWidth * Math.cos(angle),
                lastPoint.plotY + arrowWidth * Math.sin(angle),
                'Z'
            );
        }
        else
        {        
            // to the left
            path.push(
                'L',
                lastPoint.plotX - arrowWidth * Math.cos(angle),
                lastPoint.plotY + arrowWidth * Math.sin(angle)
            );
            path.push(
                lastPoint.plotX - arrowLength * Math.sin(angle),
                lastPoint.plotY - arrowLength * Math.cos(angle)
            );
            path.push(
                lastPoint.plotX + arrowWidth * Math.cos(angle),
                lastPoint.plotY - arrowWidth * Math.sin(angle),
                'Z'
            );
        }
    

    See new fiddle.

    enter image description here

    0 讨论(0)
  • 2020-12-22 07:36

    The problem is with the overriding of the original value for angle:

    angle = Math.PI+angle;
    

    Should be:

        if (lastPoint.plotX > nextLastPoint.plotX){
            if (angle < 0) angle = Math.PI + angle;
        }
        else{
            if (angle > 0) angle = Math.PI + angle;
        }
    

    Mark's point about the direction of the line was correct but the proposed solution did not always work depending on the slope of the last two points of the line.

    See fiddle

    0 讨论(0)
提交回复
热议问题