Welcome Guest Search | Active Topics |

linear gauge move needle
timhenn
#1 Posted : Friday, December 13, 2013 6:16:04 PM(UTC)
Rank: Newbie

Groups: ExpiredLicense, Registered
Joined: 12/13/2013(UTC)
Posts: 2

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Is it possible to allow the user to move the needle indicator to the customTickMarks on the linear gauge control? Is there sample code for this? I tried the event code from another control that works but there is a method (apparently part of the control??) called needleContainsPoint that isn't recognized.

Tim
maxim.milev
#2 Posted : Saturday, December 14, 2013 10:05:18 AM(UTC)
Rank: Newbie

Groups: jQueryChart, jQueryDV, jQueryGauges, Moderator, MvcChart, Registered, WebFormsChart
Joined: 1/15/2013(UTC)
Posts: 7

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi Tim,

You can change the needle value using the following code:
Code:

var scales = $('#jqLinearGauge').jqLinearGauge('option', 'scales');
                scales[0].needles[0].value = Math.random() * 100;

                $('#jqLinearGauge').jqLinearGauge('update');

Please note that you should change "Math.random() * 100" with your desired value/

Here is a working example of this: http://www.jqchart.com/j...auge/ChangeGaugeOptions


Please let me know if it works for you.


Best regards,
Maxim Milev
www.jqchart.com
timhenn
#3 Posted : Monday, December 16, 2013 9:49:07 PM(UTC)
Rank: Newbie

Groups: ExpiredLicense, Registered
Joined: 12/13/2013(UTC)
Posts: 2

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Thanks, that helped me out. I still need to figure out how to detect the needle selection with the mouse move to allow dragging the needle to the next higher or lower values but actually changing the value of the needle is pretty straight forward.

Tim
maxim.milev
#4 Posted : Tuesday, December 17, 2013 5:10:39 PM(UTC)
Rank: Newbie

Groups: jQueryChart, jQueryDV, jQueryGauges, Moderator, MvcChart, Registered, WebFormsChart
Joined: 1/15/2013(UTC)
Posts: 7

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi Tim,

Unfortunately we don't support the needle dragging feature, yet.
We will try to add it in the next version of our components.

Meanwhile you can try the following code:

Code:

$(document).ready(function () {

        var gradient1 = {
            type: 'linearGradient',
            x0: 0.5,
            y0: 0,
            x1: 0.5,
            y1: 1,
            colorStops: [{ offset: 0, color: '#C5F80B' },
                         { offset: 1, color: '#6B8901' }]
        };

        var gradient2 = {
            type: 'linearGradient',
            x0: 0.5,
            y0: 0,
            x1: 0.5,
            y1: 1,
            colorStops: [{ offset: 0, color: '#FF3366' },
                         { offset: 1, color: '#B2183E' }]
        };

        var gradient3 = {
            type: 'linearGradient',
            x0: 0.5,
            y0: 0,
            x1: 0.5,
            y1: 1,
            colorStops: [{ offset: 0, color: '#339CFF' },
                         { offset: 1, color: '#1F66A8' }]
        };

        var needleGradient = {
            type: 'linearGradient',
            x0: 0,
            y0: 0.5,
            x1: 1,
            y1: 0.5,
            colorStops: [{ offset: 0, color: '#4F6169' },
                         { offset: 1, color: '#252E32' }]
        };


        $('#jqLinearGauge').jqLinearGauge({
            orientation: 'horizontal',
            background: '#F7F7F7',
            border: {
                padding: 10,
                lineWidth: 4,
                strokeStyle: '#76786A'
            },
            tooltips: {
                disabled: false,
                highlighting: true
            },
           
            scales: [
                {
                    minimum: 0,
                    maximum: 100,
                    customTickMarks: [8, 30, 50, 70, 80, 95],
                    labels: {
                        offset: 0.16
                    },
                    majorTickMarks: {
                        length: 10,
                        offset: 0.28,
                        lineWidth: 2
                    },
                    ranges: [
                        {
                            startValue: 0,
                            endValue: 40,
                            innerOffset: 0.46,
                            outerStartOffset: 0.64,
                            outerEndOffset: 0.75,
                            fillStyle: gradient1
                        },
                        {
                            startValue: 40,
                            endValue: 70,
                            innerOffset: 0.46,
                            outerStartOffset: 0.75,
                            outerEndOffset: 0.84,
                            fillStyle: gradient2
                        },
                        {
                            startValue: 70,
                            endValue: 100,
                            innerOffset: 0.46,
                            outerStartOffset: 0.84,
                            outerEndOffset: 0.90,
                            fillStyle: gradient3
                        }
                    ],
                    needles: [
                        {
                            type: 'pointer',
                            value: 80,
                            cursor: 'pointer',
                            fillStyle: needleGradient,
                            innerOffset: 0.50,
                            outerOffset: 1.00
                        }
                    ]
                }
            ]
        });

        var handledShape = null;

        $('#jqLinearGauge').bind('mousedown', function (e, data) {

            var gauge = $('#jqLinearGauge').jqLinearGauge('linearGauge');
            var mouseInput = gauge.mouseInput;
            var shape = gauge.hitTest(mouseInput.locX, mouseInput.locY);

            if (shape.context.elementType != 'needle') {
                return;
            }

            handledShape = shape;
        });

        $('#jqLinearGauge').bind('mousemove', function (e, data) {

            if (handledShape == null) {
                return;
            }

            var gauge = $('#jqLinearGauge').jqLinearGauge('linearGauge');
            var mouseInput = gauge.mouseInput;

            var scale = handledShape.context.scale;
            var tickMarks = scale.customTickMarks;

            var mouseValue = scale.getValue(mouseInput.locX);

            var snapValue = tickMarks[0];
            var diff = Math.abs(mouseValue - snapValue);

            for (var i = 1; i < tickMarks.length; i++) {

                var vl = tickMarks[i];
                var currDiff = Math.abs(mouseValue - vl);
                if (currDiff < diff) {
                    snapValue = vl;
                    diff = currDiff;
                }
            }

            var scales = $('#jqLinearGauge').jqLinearGauge('option', 'scales');

            if (scales[0].needles[0].value != snapValue) {
                scales[0].needles[0].value = snapValue;

                $('#jqLinearGauge').jqLinearGauge('update');
            }
        });

        $('#jqLinearGauge').bind('mouseup', function (e, data) {

            handledShape = null;
        });
    });




Please let me know if this works for you.


Best regards,
Maxim Milev
www.jqchart.com
Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

FlatEarth Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.123 seconds.