Tutorial 24: Bubble Chart in C#
« on: February 04, 2016, 03:21:51 PM »
This sample uses SeriesFactory class to add bubbles to the chart using AddBubble() method.
 
Steps:

1. Create a new Windows application project (C#) and name it Tutorial24_Bubble.
2. Add Crossing Charts Library to the toolbox palette and drag it to Form1.
3. Add a button.
4. Copy and paste de following code:

Code: [Select]
using System;
using System.Windows.Forms;
using System.Drawing;
using CrossingChartsLibrary;
namespace Tutorial24_Bubble
{
public partial class Form1 : Form
{
   public Form1()
  {
      InitializeComponent();
  }
  private void Form1_Load(object sender, EventArgs e)
  {
  // Chart basic setup
  CrossingCharts1.AutoRefresh = false;
  CrossingCharts1.Style = STYLE2D3D.STYLE2D_BUBBLE;
  CrossingCharts1.Title = "Bubble Chart Sample";
  // General look & feel
  CrossingCharts1.CastShadows = false;
  CrossingCharts1.WallsBackStyle =
      STYLEWALLBACKGROUND.STYLEWALLBACKGROUND_GRADIENT_INVERTED;
  CrossingCharts1.WallsBackColorPrincipal = Color.LightSkyBlue;
  CrossingCharts1.ShowDividersX = true;
  CrossingCharts1.BackStyle = STYLEBACKGROUND.STYLEBACKGROUND_GRADIENT_TUBULAR;
  // Axis scale setup
  CrossingCharts1.XAxisScaleMinimum = 0;
  CrossingCharts1.XAxisScaleMaximum = 100;
  CrossingCharts1.XAxisScaleMode = SCALEMODE.SCALEMODE_FIXED;
  CrossingCharts1.ShowXAxis = true;
  CrossingCharts1.YAxisScaleMinimum = 0;
  CrossingCharts1.YAxisScaleMaximum = 100;
  CrossingCharts1.YAxisScaleMode = SCALEMODE.SCALEMODE_FIXED;
  CrossingCharts1.YAxisNumericFormat = "0";
  // Values setup
  CrossingCharts1.BubbleMaxRadius = 40;
  super2d3dGraph1.ShowValues = false;
  // Datatable setup
  CrossingCharts1.DataTableText = "Bubble Sizes";
  CrossingCharts1.ShowItemsLegend = true;
  CrossingCharts1.ShowLegendInDataTable = false;
  CrossingCharts1.ValuesFormat = "0";
  CrossingCharts1.DataTableFont = new Font("Arial", 11);
  CrossingCharts1.DataTableBackColor = Color.Lavender;
  // Legend setup
  CrossingCharts1.ShowLegend = false;
  // Add random values
  LoadRandomData();
  // Show it
  CrossingCharts1.RefreshChart();
  }
  private void LoadRandomData()
  {
      SeriesFactory sf = new SeriesFactory();
      Random rnd = new Random((int)DateTime.Now.Ticks);
      for (int k = 0; k < 10; k++)
      {
        sf.AddBubble(rnd.Next(80) + 10, rnd.Next(80) + 10, rnd.Next(10));
        sf.ItemColor(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)));
      }
      sf.ApplyTo(CrossingCharts1);
  }
  private void btRandomize_Click(object sender, EventArgs e)
  {
      LoadRandomData();
  }
}
}

Results:

« Last Edit: February 16, 2016, 10:16:38 AM by CrossingCharts »