<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is it possible to use Chart.JS to create a Power BI Custom visual ? in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3924216#M9653</link>
    <description>&lt;P&gt;you should import the library&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import {Chart} from 'chart.js';&lt;/LI-CODE&gt;&lt;P&gt;create a private properties for the Visual class&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;private myChart: Chart;&lt;/LI-CODE&gt;&lt;P&gt;and then at the end of your code&amp;nbsp;change that chart constant to&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ctx = 'canvasId';
        if(this.myChart)
            this.myChart.destroy();
        this.myChart = new Chart(ctx, {
            type: 'bar',
            data: barChartData,
.....
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;with your graph configuration&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2024 12:46:50 GMT</pubDate>
    <dc:creator>gdelpuenteCinec</dc:creator>
    <dc:date>2024-05-16T12:46:50Z</dc:date>
    <item>
      <title>Is it possible to use Chart.JS to create a Power BI Custom visual ?</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3888398#M9604</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I would like to use the Chart.JS library to create my visual. To do this, I referred to this tutorial:&lt;/P&gt;&lt;P&gt;&lt;A href="https://medium.com/@jatin7gupta/adding-external-js-libraries-powerbi-custom-visuals-9b0b9a7d4ae" target="_blank"&gt;https://medium.com/@jatin7gupta/adding-external-js-libraries-powerbi-custom-visuals-9b0b9a7d4ae&lt;/A&gt;&lt;BR /&gt;But when I execute &lt;FONT face="courier new,courier"&gt;pbiviz start&lt;/FONT&gt;, the visual is completely blank.&lt;BR /&gt;So I wanted to know if it is possible to use Chart.JS to develop a custom visual and if so, how can I fix my code to display the visual?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 08:48:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3888398#M9604</guid>
      <dc:creator>delphine_g</dc:creator>
      <dc:date>2024-05-03T08:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use Chart.JS to create a Power BI Custom visual ?</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3897698#M9610</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course it is possible to use external libraries like Chart.JS to create a Power BI Custom Visual and regarding the article you provided, there is a code sample that shows how to do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please provide use the code you used in your visual Class and also what is your data role/mapping?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that the example in the Medium article is using the default data role/mapping and only update the constructor and the update methods of the visual so it should be easy to reproduce so tell us what you have done and we will find how to help you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 07:16:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3897698#M9610</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-05-07T07:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use Chart.JS to create a Power BI Custom visual ?</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3913253#M9636</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;Thank you for your answer.&lt;BR /&gt;Here's the Datarole/Mapping I used :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"dataRoles": [
        {
            "displayName": "Categories",
            "name": "category",
            "kind": "Grouping"
        },
        {
            "displayName": "Right Values",
            "name": "right_value",
            "kind": "Measure"
        },
        {
            "displayName": "Left Values",
            "name": "left_value",
            "kind": "Measure"
        }
    ],
"dataViewMappings": [
        {
            "conditions": [
                {
                    "category": {
                        "max": 1
                    },
                    "right_value": {
                        "max": 1
                    },
                    "left_value": {
                        "max": 1
                    }
                }
            ],
            "categorical": {
                "categories": {
                    "for": {
                        "in": "category"
                    },
                    "dataReductionAlgorithm": {
                        "top": {}
                    }
                },
                "values": {
                    "select": [
                        {
                            "bind": {
                                "to": "right_value"
                            }
                        },
                        {
                            "bind": {
                                "to": "left_value"
                            }
                        }
                    ]
                }
            }
        }
    ],&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And this is the code I used for my visual Class :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export class Pyramid implements IVisual {
    private target: HTMLElement;
    private updateCount: number;

    constructor(option : VisualConstructorOptions) {
        console.log('Visual constructor', option);
            this.target = option.element;
            this.updateCount = 0;
            if (typeof document !== "undefined") {
                const new_p: HTMLElement = document.createElement("div");
                const can: HTMLElement = document.createElement("canvas");
                can.setAttribute("id", "canvasId");
                new_p.appendChild(can);
                this.target.appendChild(new_p);
            }
        
    }
    public update(option : VisualUpdateOptions) {
        const extracted_data = [] ;   
        if(option.dataViews 
            &amp;amp;&amp;amp; option.dataViews[0] 
            &amp;amp;&amp;amp;  option.dataViews[0].categorical
            &amp;amp;&amp;amp;  option.dataViews[0].categorical.categories
            &amp;amp;&amp;amp;  option.dataViews[0].categorical.values
            ) {               
        const categoricalData = option.dataViews[0].categorical;
        const category = categoricalData.categories[0] ;
        const right_value = categoricalData.values[0]; 
        const left_value = categoricalData.values[1]; 

        for (let i = 0; i&amp;lt; category.values.length; i++){
            extracted_data.push({
                category: category.values[i],
                rvalue: right_value.values[i], //blue values
                lvalue: left_value.values[i] , //red values
            });
        }}
        
        const labels = extracted_data.map(dataPoint =&amp;gt; dataPoint.category);
        const data = {
          labels: labels,
          datasets: [{
            label: 'Right Data',
            data: extracted_data.map(dataPoint =&amp;gt; dataPoint.rvalue),            
            borderColor: '#33B0FF',
            backgroundColor: '#33B0FF',
            borderWidth: 1
          },
          {
            label: 'Left Data',
            data: extracted_data.map(dataPoint =&amp;gt;  dataPoint.lvalue * -1),            
            borderColor: '#FF33BD',
            backgroundColor: '#FF33BD',            
            borderWidth: 1
          }]
        };
            let d = (&amp;lt;any&amp;gt;window).Chart;

            const chart = {
                type: 'bar',
                data: data,
                options: {
                  inexAxis : 'y',
                  scales: {
                    x: {
                      stacked: true
                    },
                    y: {
                      beginAtZero: true,
                      stacked: true
                    }
                  }
                },
              };
    }
}
    &lt;/LI-CODE&gt;&lt;P&gt;Can you help me to find what's wrong here please ?&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 08:14:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3913253#M9636</guid>
      <dc:creator>delphine_g</dc:creator>
      <dc:date>2024-05-13T08:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use Chart.JS to create a Power BI Custom visual ?</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3924216#M9653</link>
      <description>&lt;P&gt;you should import the library&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import {Chart} from 'chart.js';&lt;/LI-CODE&gt;&lt;P&gt;create a private properties for the Visual class&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;private myChart: Chart;&lt;/LI-CODE&gt;&lt;P&gt;and then at the end of your code&amp;nbsp;change that chart constant to&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ctx = 'canvasId';
        if(this.myChart)
            this.myChart.destroy();
        this.myChart = new Chart(ctx, {
            type: 'bar',
            data: barChartData,
.....
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;with your graph configuration&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 12:46:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3924216#M9653</guid>
      <dc:creator>gdelpuenteCinec</dc:creator>
      <dc:date>2024-05-16T12:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use Chart.JS to create a Power BI Custom visual ?</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3924637#M9656</link>
      <description>&lt;P&gt;The import was wrong :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import {Chart} from 'chart.js';&lt;/LI-CODE&gt;&lt;P&gt;I change it for :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Chart from "chart.js/auto"; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And with the rest of your solution it worked !&lt;BR /&gt;Thank you&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 16:09:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Is-it-possible-to-use-Chart-JS-to-create-a-Power-BI-Custom/m-p/3924637#M9656</guid>
      <dc:creator>delphine_g</dc:creator>
      <dc:date>2024-05-16T16:09:00Z</dc:date>
    </item>
  </channel>
</rss>

