OHLC Bar Chart

 

 

Version Info

Minimum Origin Version Required: Origin8.5 SR0

Example

  1. Download the source data file from our ftp and import it into Origin. When importing this file, keep the system default settings.
  2. Rename the short name of both workbook and worksheet to “OHLC”.
  3. Set column A as Date format. Double click on the header of column A to bring up the Column Properties dialog. Expand the Options branch in Properties tab, select Date from the Format drop-down list, and then select Custom Display from the Display drop-down list. Type dd'-'MMM'-'yyyy in the Custom Display combo box. Click OK button.
    Column Properties.png
  4. Compile and run the following function plot to a OHLC bar chart.
    void plot_OHLC_bar_chart_ex1()
    {
        GraphPage gp;
        gp.Create();
        GraphLayer gl = gp.Layers();
        if(!gl)
            return;
     
        // Draw an OHLC bar chart
        Tree tr;
        TreeNode trLayer = tr.AddNode("Layer0");
        trLayer.Rescale.nVal = 1;
     
        TreeNode trDataPlot = trLayer.AddNode("DataPlot1");
        trDataPlot.PlotType.strVal = "OHLC";
     
        TreeNode trDesigs = trDataPlot.AddNode("PlotDesigs");
        trDesigs.Type.nVal = 221;
        trDesigs.ExValue.nVal = 1;
     
        // Specify the workbook and worksheet in order to point to the data.
        trDesigs.WksPage.strVal = "OHLC";
        trDesigs.WksLayer.strVal = "OHLC";
     
        // Name the tree node with a prefix "DPC..."
        TreeNode trOpen = trDesigs.AddNode("DPC1");
        trOpen.Desig.nVal = COLDESIG_OPEN;
        trOpen.Name.strVal = "B";
     
        TreeNode trHi = trDesigs.AddNode("DPC2");
        trHi.Desig.nVal = COLDESIG_HIGH;
        trHi.Name.strVal = "C";
     
        TreeNode trLo = trDesigs.AddNode("DPC3");
        trLo.Desig.nVal = COLDESIG_LOW;
        trLo.Name.strVal = "D";
     
        TreeNode trClose = trDesigs.AddNode("DPC4");
        trClose.Desig.nVal = COLDESIG_CLOSE;
        trClose.Name.strVal = "E";
     
        TreeNode trX = trDesigs.AddNode("DPC5");
        trX.Desig.nVal = COLDESIG_X;
        trX.Name.strVal = "A";
     
        gl.AddPlots(tr.Layer0);
        
        // Customize the graph layer format
        Tree trFormat;
            trFormat.Root.Axes.X.Scale.Type.nVal = 11;
            trFormat.Root.Axes.X.Labels.BottomLabels.Font.Size.nVal = 12; 
            trFormat.Root.Axes.X.Labels.BottomLabels.Type.nVal = 3;
            trFormat.Root.Axes.X.Labels.BottomLabels.DateFormat.nVal = 21;
            trFormat.Root.Axes.X.Labels.BottomLabels.DateCustomDisplay.strVal = "dd'-'MMM'-'yyyy";
            trFormat.Root.Axes.X.Labels.BottomLabels.Angle.nVal = 45;
            trFormat.Root.Axes.Y.Labels.LeftLabels.Font.Size.nVal = 12; 
    
        if(0 == gl.UpdateThemeIDs(trFormat.Root))
            bool bRet = gl.ApplyFormat(trFormat, true, true); // Update the graph layer format
        if(bRet)     
            out_tree(gl.GetFormat(FPB_ALL, FOB_ALL, true, true)); //Output the whole format tree  
    }