기능

chart에 value를 동적으로 추가

backgroundColor를 랜덤하게 설정 ( 결과가 Fix 되지않은 chart 리스트를 추가 할때 사용 )

 

// html
<canvas id="cChart"></canvas>

// javascript
var Chart_ctx = document.getElementById('cChart').getContext('2d');

// Chart Config
Chart_config = {
    type: 'pie',
    data: ..........
}

// Chart Create
var Chart = new Chart(Chart_ctx, Chart_config);


// Chart Data 동적 추가
Chart_config.data.datasets[0].data.push(1);

// Set backgroundColor 랜덤하게 값 추가 ( 투명도 30% )
var RGB_1 = Math.floor(Math.random() * (255 + 1))
var RGB_2 = Math.floor(Math.random() * (255 + 1))
var RGB_3 = Math.floor(Math.random() * (255 + 1))
var strRGBA = 'rgba(' + RGB_1 + ',' + RGB_2 + ',' + RGB_3 + ',0.3)'
Chart_config.data.datasets[0].backgroundColor.push(strRGBA);

참고

https://stackoverflow.com/questions/23095637/how-do-you-get-random-rgb-in-javascript

기능

1. Chart.js 2.x 버전 Pie Chart

2. 파이 차트 클릭 이벤트 ( Pie Chart Click Event ) - label 및 value 조회

3. 마우스 오버없이 레이블을 항상 백분율(%)값을 표시

 

html

* chart를 그리기 위한 canvas를 생성

* 다른 로직에서 canvas를 참고하기 위해 id를 지정 ( 예제는 cPieChart 으로 생성 )

<canvas id="cPieChart" style="min-height: 500px; height: 500px; max-height: 1000px; width: 700px; max-width: 100%;"></canvas>

javascript

* chart.js를 사용하기 위해 Chart.min.js 를 추가

* 마우스 오버없이 레이블을 항상 표시하기 위한 chartjs-plugin-datalabels@0.7.0 추가

 

* config의 data -> datasets -> datalabels 부분에 설정값을 지정

   align : 레이블 위치

   backgroundColor : ctx 정보를 가져와서 value가 0 이상인 경우만 출력

   color : ctx 정보를 가져와서 value가 0 이상인 경우만 출력

   formatter : value, ctx 정보를 가져와서 0 이상인 경우 백분율값을 구하여 리턴

 

* Pie Chart 생성 후 onClick Event 값을 가져와서 이벤트 처리

  getElementsAtEvent(evt) 함수로 클릭 이벤트 값을 조회

  activePoints[0]["_index"] 로 클릭한 차트의 위치값을 조회

   >> 만약 하나의 canvas에 여러개의 chart가 있는 경우 아래 형태로 조회

        activePoints[0]["_index"]

        activePoints[1]["_index"]

        activePoints[2]["_index"]

 

<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.7.0"></script>

// Pie Chart ctx Get
var PieChart_ctx = document.getElementById('cPieChart').getContext('2d');

// Pie Chart Config Set
PieChart_config = {
    type: 'pie',
    data: {
        labels: ['OPEN', 'PROGRESSING', 'COMPLETE'],
        data: [13,11,14],
        datasets: [{
            label: 'Pie Chart Count',
            backgroundColor: [
                        'rgba(255, 99, 132, 0.2)',
                        'rgba(54, 162, 235, 0.2)',
                        'rgba(75, 192, 192, 0.2)'
                        ],
            borderColor: [
                        'rgba(255, 99, 132, 1)',
                        'rgba(54, 162, 235, 1)',
                        'rgba(75, 192, 192, 1)'
                        ],
            borderWidth: 1,
            datalabels: {
                labels: {
                    value: {
                        borderWidth: 2,
                        borderRadius: 4,
                        font: {size: 15},
                        formatter: function(value, ctx) {
                            var value = ctx.dataset.data[ctx.dataIndex];
                            return value > 0 ? Math.round(value / (ctx.dataset.data[0] + ctx.dataset.data[1] + ctx.dataset.data[2]) * 100) + ' %' : null;
                        },
                        color: function(ctx) {
                            var value = ctx.dataset.data[ctx.dataIndex];
                            return value > 0 ? 'white' : null;
                        },
                        backgroundColor:function(ctx) {
                            var value = ctx.dataset.data[ctx.dataIndex];
                            return value > 0 ? 'gray' : null;
                        },
                        padding: 4
                    }
                }
            }
        }]
    },
    options: {
        responsive: true,
        maintainAspectRatio : false,
        animation: false,
        legend: {
            position: 'left',
            display: true
        },
        title: {
            display: false,
            text: 'Pie Chart - Count',
            font: {
                size: 50
            },
            fontstyle: 'bold',
            position: 'top'
        }, 
        plugins: {
            legend: {
                position: 'left',
            },
            title: {
                display: true,
                text: 'Pie Chart - Count',
                font: { 
                    size: 25
                }
            }
        }
    }
};


// Pie Chart Create
var PieChart = new Chart(PieChart_ctx, PieChart_config);

// Pie Chart Event Set
document.getElementById("cPieChart").onclick = function(evt) {

    var activePoints = PieChart.getElementsAtEvent(evt);

    if(activePoints.length > 0)
    {
        //get the internal index of slice in pie chart
        var clickedElementindex = activePoints[0]["_index"];

        //get specific label by index 
        var label = PieChart.data.labels[clickedElementindex];

        //get value by index      
        var value = PieChart.data.datasets[0].data[clickedElementindex];

        // label and value Process
        
   }
};

참고

https://stackoverflow.com/questions/26257268/click-events-on-pie-charts-in-chart-js

https://chartjs-plugin-datalabels.netlify.app/samples/charts/line.html

https://chartjs-plugin-datalabels.netlify.app/samples/advanced/multiple-labels.html

 

Multiple Labels | chartjs-plugin-datalabels

Multiple Labels Use multiple labels configuration to display 3 labels per data, one for the index, one for the label and one for the value. Move the mouse over the chart to display label ids. { type: 'doughnut', data: { labels: labels, datasets: [{ backgro

chartjs-plugin-datalabels.netlify.app

 

현재 max worker threads 카운트 확인 및 수정

USE AdventureWorks2012 ;  
GO  
EXEC sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE ;  
GO

-- 정보 확인
EXEC sp_configure 'max worker threads'

-- max worker threads를 900으로 변경
EXEC sp_configure 'max worker threads', 900 ;  
GO  
RECONFIGURE;  
GO

CPU Core별 사용 가능 카운트

CPU 수 32비트 컴퓨터(최대 SQL Server 2014(12.x)) 64비트 컴퓨터(최대 SQL Server 2016(13.x) SP1) 64비트 컴퓨터(SQL Server 2016(13.x) SP2 및 SQL Server 2017(14.x)부터)
< = 4 256 512 512
8 288 576 576
16 352 704 704
32 480 960 960
64 736 1472 1472
128 1248 2496 4480
256 2272 4544 8576

참고

https://docs.microsoft.com/ko-kr/sql/database-engine/configure-windows/configure-the-max-worker-threads-server-configuration-option?view=sql-server-ver15

 

max worker threads 서버 구성 옵션 구성 - SQL Server

최대 작업자 스레드 옵션을 사용하여 SQL Server에서 특정 요청을 처리하는 데 사용할 수 있는 작업자 스레드 수를 구성하는 방법을 알아봅니다.

docs.microsoft.com


to Top