2013-08-22 3 views
2

http://jsfiddle.net/r6p7E/6/을 선택하면 선택할 때마다 같은 색상으로 선택된 섹션이 표시됩니다. 나는 이것을 클릭 할 때만 노란색으로하고 싶다.부품을 하이 컬러로 표시 할 때이 부품을 클릭했을 때

코드 : http://jsfiddle.net/L5SXX/

당신은 allowPointSelect 켜고 다음 선택 상태에 대한 색상을 추가해야

$(function() { 

      Highcharts.theme = { 
      colors: ['#242c4a'], 
      chart: { 
      width: 350, 
       backgroundColor: { 
        linearGradient: [0, 0, 500, 500], 
        stops: [ 
         [0, 'rgb(255, 255, 255)'], 
         [1, 'rgb(240, 240, 255)'] 
        ] 
       }, 
      }, 

     }; 

     // Apply the theme 
     Highcharts.setOptions(Highcharts.theme); 

     // Build the chart 
     $('#container').highcharts({ 
      chart: { 
       plotBackgroundColor: null, 
       plotBorderWidth: null, 
       plotShadow: false 
      }, 
      title: { 
       text: 'Our Projects' 
      }, 

      plotOptions: { 

       pie: { 


        borderColor: '#48588c', 
        borderWidth: 7, 
        slicedOffset: 10,      
        allowPointSelect: true, 
        cursor: 'pointer', 
        dataLabels: { 
         enabled: false 

        } 

       }, 

       series: { 

       point: { 
        events: { 
         select: function() { 

         } 
        } 
       } 
      } 


      }, 
       series: [{ 
       type: 'pie', 
       name: 'Browser share', 
       dashStyle: 'LongDashDotDot', 
       data: [ 
        ['Firefox', 45.0], 
        ['IE',  26.8], 
        { 
         name: 'Chrome', 
         y: 12.8, 
         sliced: true, 
         selected: true 
        }, 
        ['Safari', 8.5], 
        ['Opera',  6.2], 
        ['Others', 0.7] 
       ] 
      }] 
     }, 

     function(chart) { // on complete 


     var renderer = new Highcharts.Renderer(
      $('#container')[0], 50, 50); 

     chart.renderer.circle(175, 216, 22).attr({ 
      fill: '#e7e620', 

      'stroke-width': 5, 
      zIndex: 3 
     }).add(); 
     } 



     ); 
    }); 
+0

당신이 마우스를 가져 가면 당신 만 변경 색상을 원하지 않는 건가요 클릭 할 때 변경하고 싶습니까? 또한 클릭 할 때 모든 피스가 같은 색 (노랑색)으로 나타나도록 하시겠습니까? 아니면 각 피스를 자신의 색으로 보이기를 원하십니까? –

+0

나는 클릭 한 부분을 노란색으로하고 다른 부분은 변경하지 않기를 바란다. – OOOO

답변

5

실제로 원하는 것일 수 있습니다. 그러나이 바이올린을 요청 내용에 따라 그 당신에게 제공 : 물론

point: { 
    events: { 
     click: function() { 
      this.graphic.attr({ 
       fill: 'yellow' 
      }); 
     } 
    } 
}, 

가 mouseOut 이벤트는 일단 색상을 죽이고 : http://jsfiddle.net/r6p7E/8/가 대신 mouseOver 이벤트의

, 당신은 클릭 이벤트에 그것을 변경할 수 있습니다 멀리 이동하지만 당신이 그것을 언급하지 않았 으면 그것이 당신이 원하거나 그렇지 않은지 확실하지 않습니다.

편집 :이 바이올린은 선택되지 않은 때까지 노란색의 색상을 유지 (또는 다른 선택됩니다) : http://jsfiddle.net/r6p7E/12/

allowPointSelect: true, 
slicedOffset: 0, 
point: { 
    events: { 
     select: function() { 
      this.update({color: 'yellow'}); 
     }, 
     unselect: function() { 
      this.update({color: '#CCCCCC'}); 
     } 
    } 
} 
+0

마우스 커서가 원형이 아닐지라도 색을 유지하고 싶습니다. – OOOO

+0

감사! 이 같은 http://jsfiddle.net/r6p7E/9/해야합니다. – OOOO

+1

slicedOffset : 0 - 원형 슬라이스가 계속 슬라이딩되지 않도록 유지합니다. –

2

이 바이올린을 참조하십시오. mouseOver 및 mouseOut 작업을 수행하기 때문에 선택한 색상을 유지하려면 약간의 수정이 필요합니다.

plotOptions: { 

     series: { 
      allowPointSelect : true, 
      slicedOffset: 0, 
      states: { 
       select: { 
        color: 'yellow' 
       }, 
       hover: { 
        enabled: false 
       } 
      }, 
      point: { 
       events: { 
        mouseOver: function() { 
         this.graphic.attr({ 
          fill: 'red' 
         }); 
        } 
       } 
      }, 
      events: { 
       mouseOut: function() { 
        var serie = this.points; 

        $.each(serie, function (i, e) { 
         if (!this.selected) {          
          this.graphic.attr({ 
           fill: '#CCCCCC' 
          }); 
         } 
         else { 
          this.graphic.attr({ 
           fill: 'yellow' 
          }); 
         } 
        }); 
       } 
      } 
     } 
    }, 
+0

제안 해 주셔서 감사합니다.하지만 선택한 색상을 유지하려면 어떻게해야합니까? – OOOO

+0

이 코드는 마우스를 끈 후에 선택한 색상으로 되돌립니다. 마우스를 올려 놓더라도 노란색으로 보이기를 원하십니까? 그렇다면 선택한 부분의 색상을 변경하지 않으려면 if (! this.selected)를 mouseOver 코드에 추가하십시오. –

관련 문제