Custom Legend for Column Chart, with pointColorMapping and only a single serie with Color parameter

Capturar.PNG Hello,

 How do I insert the legend for this type of chart (a single serie with 4 colors...) ?

  I think I have to use "Custom Legend" but don't know how!

   I try...   


 <div class="mr-2 mt-2">

        <ejs-chart id="GraficoDiario" title="@Model.TituloGrafico">

            <e-chart-tooltipsettings enable="true">

            </e-chart-tooltipsettings>


            <e-chart-primaryxaxis title="horas" valueType="Category" labelIntersectAction="Rotate45" interval=4>

                <e-majorgridlines width="0"></e-majorgridlines>

            </e-chart-primaryxaxis>


            <e-chart-primaryyaxis title="@ViewBag.unidade" labelFormat="n3"></e-chart-primaryyaxis>


            <e-chart-legendsettings visible="true" toggleVisibility="false" position="Bottom" maximumTitleWidth="300" title="Super Vazio"></e-chart-legendsettings>



            <e-chart-chartarea>

                <e-chartarea-border width="0"></e-chartarea-border>

            </e-chart-chartarea>


            <e-chart-zoomsettings enableMouseWheelZooming="true" enablePinchZooming="true" enableSelectionZooming="true"></e-chart-zoomsettings>



            <e-series-collection>

                <e-series dataSource="ViewBag.dataSource" name=" " xName='x' yName='yValue' width=2 pointColorMapping="Color" type="Column">

                    <e-series-marker>

                        <e-series-datalabel visible="false" position="Top">

                            <e-font color="#ffffff" fontWeight="600"></e-font>

                        </e-series-datalabel>

                    </e-series-marker>

                </e-series>

            </e-series-collection>


        </ejs-chart>

    </div>


3 Replies

DG Durga Gopalakrishnan Syncfusion Team November 16, 2021 02:37 PM UTC

Hi Pedro, 

Greetings from Syncfusion. 

We request you to use chart annotations to achieve your requirement. We have prepared sample based on your requirement. Please check with below snippet and sample. 

@{ 
    string valueX = "45%"; 
} 
<ejs-chart> 
    <e-chart-margin bottom="30"></e-chart-margin> 
    <e-chart-annotations> 
        <e-chart-annotation content="#templateWrap" region="Chart" x=valueX y="98%"></e-chart-annotation> 
    </e-chart-annotations> 
</ejs-chart> 
<script id="templateWrap" type="text/x-template"> 
    <div style="width:80px; padding: 5px;"> 
      //…. 
    </div> 
</script> 

 




Please let us know if you have any concerns. 

Regards,  
Durga G 



PA pedro alegria replied to Durga Gopalakrishnan November 16, 2021 05:41 PM UTC

It's working but when exporting graph to pdf the anottation "legend" disappears in pdf...


Thanks



DG Durga Gopalakrishnan Syncfusion Team November 17, 2021 02:57 PM UTC

Hi Pedro, 

As of now, we don’t have support to export annotations in chart. We request you to convert annotation elements into foreign object and append it to chart SVG. Then using pdfexport method, you can draw an image into PDF. Please check with the below snippet and sample. 

document.getElementById('button').onclick = () => { 
//… 
for (var i = 0; i < annotationEle.length; i++) { 
             var foreign = document.createElementNS( 
                 http://www.w3.org/2000/svg, 
                 "foreignObject" 
             ); 
             //… 
             var svg = document.querySelector("#container_svg"); 
             svg.appendChild(foreign); 
         } 
         img.onload = function () { 
             ctx.drawImage(img, 0, 0); 
             var imagedata = canvas.toDataURL("image/jpeg"); 
             imagedata = imagedata.replace("data:image/jpeg;base64,", ''); 
             var image = new ejs.pdfexport.PdfBitmap(imagedata); 
             var document = new ejs.pdfexport.PdfDocument(); 
             document.pageSettings.orientation = ejs.pdfexport.PdfPageOrientation.Landscape; 
             // specify the size 
             document.pageSettings.size = new ejs.pdfexport.SizeF(1200, 600); 
             //Add a page. 
             var page1 = document.pages.add(); 
             page1.graphics.drawImage(image, 0, 0); 
             //Save the document. 
             document.save("Chart.pdf"); 
             document.destroy(); 
             canvas.remove(); 
         }; 
        }; 
</script> 

Exported PDF : 
 


Please let us know if you have any concerns. 

Regards, 
Durga G

Loader.
Up arrow icon