//+------------------------------------------------------------------+
//| PieChartSample.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Exemple d'utilisation d'un diagramme circulaire"
//---
#include <Canvas\Charts\PieChart.mqh>
//+------------------------------------------------------------------+
//| entrйes |
//+------------------------------------------------------------------+
input int Width=600;
input int Height=450;
//+------------------------------------------------------------------+
//| Fonction de dйmarrage du script |
//+------------------------------------------------------------------+
int OnStart(void)
{
//--- vйrifications
if(Width<=0 || Height<=0)
{
Print("Trop simple.");
return(-1);
}
//--- crйe le graphique
CPieChart pie_chart;
if(!pie_chart.CreateBitmapLabel("PieChart",10,10,Width,Height))
{
Print("Erreur de crйation du diagramme circulaire : ",GetLastError());
return(-1);
}
pie_chart.ShowPercent();
//--- dessin
for(uint i=0;i<30;i++)
{
pie_chart.ValueAdd(100*(i+1),"Item "+IntegerToString(i));
Sleep(10);
}
Sleep(2000);
//--- dйsactive la lйgende
pie_chart.LegendAlignment(ALIGNMENT_LEFT);
Sleep(2000);
//--- dйsactive la lйgende
pie_chart.LegendAlignment(ALIGNMENT_RIGHT);
Sleep(2000);
//--- dйsactive la lйgende
pie_chart.LegendAlignment(ALIGNMENT_TOP);
Sleep(2000);
//--- dйsactive la lйgende
pie_chart.ShowLegend(false);
Sleep(2000);
//--- dйsactive les pourcentages
pie_chart.ShowPercent(false);
Sleep(2000);
//--- dйsactive lees descripteurs
pie_chart.ShowDescriptors(false);
Sleep(2000);
//--- active tout
pie_chart.ShowLegend();
pie_chart.ShowValue();
pie_chart.ShowDescriptors();
Sleep(2000);
//--- ou de cette faзon
pie_chart.ShowFlags(FLAG_SHOW_LEGEND|FLAG_SHOW_DESCRIPTORS|FLAG_SHOW_PERCENT);
uint total=pie_chart.DataTotal();
//--- joue avec les valeurs
for(uint i=0;i<total && !IsStopped();i++)
{
pie_chart.ValueUpdate(i,100*(rand()%10+1));
Sleep(1000);
}
//--- joue avec les couleurs
for(uint i=0;i<total && !IsStopped();i++)
{
pie_chart.ColorUpdate(i%total,RandomRGB());
Sleep(1000);
}
//--- rotation
while(!IsStopped())
{
pie_chart.DataOffset(pie_chart.DataOffset()+1);
Sleep(200);
}
//--- fin
pie_chart.Destroy();
return(0);
}
//+------------------------------------------------------------------+
//| Couleur RGB alйatoire |
//+------------------------------------------------------------------+
uint RandomRGB(void)
{
return(XRGB(rand()%255,rand()%255,rand()%255));
}
|