I have a data table that has three columns: Text, Value1, Value2
I need to create a bar chart of Text (as x axis label) and Value1 as the height of the bar... and I would like to use Value2 to color the bar based on a formula.
When I load the datatable as the chart datasource, it creates two bar charts, one for value1 and one for value2. So I have a few questions:
1. How do I indicate exactly which columns are meant to be the x and y axis (with a databind, or remove or something) but I dont want to have to "load" the datapoints by iteration (which would kill the point of having a bindable control).
2. How do I intercept the paint (or some other method) to paint the bar a specific color (the number for the value2 will be used to decide)
I spent a lot of time with the examples, but frankly they show a few things, but aren't very useful.
I hope you have help
Thanks
Jeff
Looks like this is ending up in an infinite loop.
The result looks fine but the "box.PE.Fill = myColor;" seems to fire the ChartDrawItem event again and again...
Realy so much thank you, regards. The solution is good
You can do this with one of our color models. CustomLinear model should fit pretty well here. You set the color model of the chart to CustomLinear, then define an array of colors that you want the chart to use. You should see that each of the lines in the chart will use colors from the array. Here's an example:
Color[] colors = { Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Black, Color.Violet };ultraChart1.ColorModel.ModelStyle = ColorModels.CustomLinear;ultraChart1.ColorModel.CustomPalette = colors;
Hello Max, i don't know if you can help me; How is the properties to change the line color to control igchart:UltraChart?, the type chart is LineChart and i have 4 line to graphics and i need for line 1 a color blue and second line a color red and line 3 a color blue and line 4 a color red, but i don't know if i can change this properties to the graphic. Nice to meet you, this is my code:
<igchart:UltraChart ID="ucAudiometria" runat="server" EmptyChartText="" ForeColor="Black" BackColor="White" EnableCrossHair="false" EnableScrollBar="false" ChartType="LineChart" Version="5.3" Width="475" Height="300">
<Border CornerRadius="5" DrawStyle="Solid" Raised="False" Color="Black" Thickness="1"></Border>
<TitleRight Font="Microsoft Sans Serif, 7.8pt" Visible="False" Text="" FontSizeBestFit="False" Orientation="VerticalRightFacing" WrapText="False" Extent="26" FontColor="Black" HorizontalAlign="Near" VerticalAlign="Center" Location="Right">
<Margins Bottom="5" Left="5" Top="5" Right="5"></Margins>
</TitleRight>
<Data DataMember="" SwapRowsAndColumns="False" UseMinMax="False" UseRowLabelsColumn="False" MinValue="-1.7976931348623157E+308" RowLabelsColumn="-1" ZeroAligned="False" MaxValue="1.7976931348623157E+308">
<EmptyStyle Text="Empty" EnableLineStyle="False" ShowInLegend="False" EnablePE="False" EnablePoint="False">
<PointPE FillGradientStyle="None" FillOpacity="255" FillStopOpacity="255" ElementType="SolidFill" Fill="Transparent" Hatch="None" Texture="LightGrain" ImageFitStyle="StretchedFit" FillStopColor="Transparent" StrokeOpacity="255" ImagePath="" Stroke="Black" StrokeWidth="1" ImageWrapMode="Tile" TextureApplication="Normal"></PointPE>
<PointStyle CharacterFont="Microsoft Sans Serif, 7.8pt"></PointStyle>
<LineStyle MidPointAnchors="False" EndStyle="NoAnchor" DrawStyle="Dash" StartStyle="NoAnchor"></LineStyle>
<PE FillGradientStyle="None" FillOpacity="255" FillStopOpacity="255" ElementType="SolidFill" Fill="Transparent" Hatch="None" Texture="LightGrain" ImageFitStyle="StretchedFit" FillStopColor="Transparent" StrokeOpacity="255" ImagePath="" Stroke="Black" StrokeWidth="1" ImageWrapMode="Tile" TextureApplication="Normal"></PE>
</EmptyStyle>
</Data>
<TitleLeft Font="Microsoft Sans Serif, 7.8pt" Visible="False" Text="" FontSizeBestFit="False" Orientation="VerticalLeftFacing" WrapText="False" Extent="26" FontColor="Black" HorizontalAlign="Near" VerticalAlign="Center" Location="Left">
</TitleLeft>
<ColorModel ColorBegin="Blue" ColorEnd="Red" ModelStyle="LinearRange" Grayscale="False" Scaling="None">
</ColorModel>
<Legend Font="Microsoft Sans Serif, 7.8pt" Visible="False" AlphaLevel="150" BorderThickness="1" BorderStyle="Solid" SpanPercentage="25" BorderColor="Navy" FontColor="Black" BackgroundColor="FloralWhite" DataAssociation="DefaultData" Location="Right" FormatString="<ITEM_LABEL>">
</Legend>
<ColumnChart SeriesSpacing="1" ColumnSpacing="0" NullHandling="Zero"></ColumnChart>
<Axis BackColor="Cornsilk">
<Y LineEndCapStyle="NoAnchor" LineDrawStyle="Solid" Visible="False" RangeMin="0" LineColor="Black" RangeType="Automatic" TickmarkInterval="10" LineThickness="1" Extent="40" LogBase="10" RangeMax="0" TickmarkStyle="Smart" TickmarkPercentage="10" NumericAxisType="Linear">
<StripLines Interval="2" Visible="False">
</StripLines>
<ScrollScale Scale="1" Scroll="0" Height="10" Width="15" Visible="False"></ScrollScale>
<Labels ItemFormatString="<DATA_VALUE:00.##>" VerticalAlign="Center" WrapText="False" FontSizeBestFit="False" SeriesFormatString="<SERIES_LABEL>" ClipText="True" Font="Verdana, 7pt" Flip="False" ItemFormat="DataValue" FontColor="Black" Orientation="Horizontal" Visible="True" OrientationAngle="0" HorizontalAlign="Far">
<SeriesLabels Font="Microsoft Sans Serif, 7.8pt" Visible="True" HorizontalAlign="Center" FontSizeBestFit="False" ClipText="True" FormatString="<SERIES_LABEL>" Orientation="VerticalLeftFacing" WrapText="False" Flip="False" FontColor="Black" VerticalAlign="Near" OrientationAngle="0"></SeriesLabels>
</Labels>
<MajorGridLines AlphaLevel="255" DrawStyle="Dot" Color="Gainsboro" Visible="True" Thickness="1"></MajorGridLines>
<MinorGridLines AlphaLevel="255" DrawStyle="Dot" Color="LightGray" Visible="False" Thickness="1"></MinorGridLines>
<TimeAxisStyle TimeAxisStyle="Continuous"></TimeAxisStyle>
<Margin>
<Far MarginType="Percentage" Value="0"></Far>
<Near MarginType="Percentage" Value="0"></Near>
</Margin>
</Y>
<Y2 LineEndCapStyle="NoAnchor" LineDrawStyle="Solid" Visible="False" RangeMin="0" LineColor="Black" RangeType="Automatic" TickmarkInterval="10" LineThickness="2" Extent="40" LogBase="10" RangeMax="0" TickmarkStyle="Smart" TickmarkPercentage="10" NumericAxisType="Linear">
<Labels ItemFormatString="<DATA_VALUE:00.##>" VerticalAlign="Center" WrapText="False" FontSizeBestFit="False" SeriesFormatString="<SERIES_LABEL>" ClipText="True" Font="Microsoft Sans Serif, 7.8pt" Flip="False" ItemFormat="DataValue" FontColor="Black" Orientation="Horizontal" Visible="True" OrientationAngle="0" HorizontalAlign="Near">
<SeriesLabels Font="Microsoft Sans Serif, 7.8pt" Visible="True" HorizontalAlign="Near" FontSizeBestFit="False" ClipText="True" FormatString="<SERIES_LABEL>" Orientation="VerticalLeftFacing" WrapText="False" Flip="False" FontColor="Black" VerticalAlign="Center" OrientationAngle="0"></SeriesLabels>
</Y2>
<X2 LineEndCapStyle="NoAnchor" LineDrawStyle="Solid" Visible="False" RangeMin="0" LineColor="Black" RangeType="Automatic" TickmarkInterval="0" LineThickness="2" Extent="80" LogBase="10" RangeMax="0" TickmarkStyle="Percentage" TickmarkPercentage="10" NumericAxisType="Linear">
<Labels ItemFormatString="<ITEM_LABEL>" VerticalAlign="Center" WrapText="False" FontSizeBestFit="False" SeriesFormatString="<SERIES_LABEL>" ClipText="True" Font="Microsoft Sans Serif, 7.8pt" Flip="False" ItemFormat="ItemLabel" FontColor="Black" Orientation="VerticalLeftFacing" Visible="True" OrientationAngle="0" HorizontalAlign="Near">
<SeriesLabels Font="Microsoft Sans Serif, 7.8pt" Visible="True" HorizontalAlign="Near" FontSizeBestFit="False" ClipText="True" FormatString="<SERIES_LABEL>" Orientation="Horizontal" WrapText="False" Flip="False" FontColor="Black" VerticalAlign="Center" OrientationAngle="0"></SeriesLabels>
</X2>
<Z2 LineEndCapStyle="NoAnchor" LineDrawStyle="Solid" Visible="False" RangeMin="0" LineColor="Black" RangeType="Automatic" TickmarkInterval="0" LineThickness="2" Extent="80" LogBase="10" RangeMax="0" TickmarkStyle="Percentage" TickmarkPercentage="10" NumericAxisType="Linear">
<Labels ItemFormatString="" VerticalAlign="Center" WrapText="False" FontSizeBestFit="False" SeriesFormatString="<SERIES_LABEL>" ClipText="True" Font="Microsoft Sans Serif, 7.8pt" Flip="False" ItemFormat="None" FontColor="Black" Orientation="Horizontal" Visible="True" OrientationAngle="0" HorizontalAlign="Near">
</Z2>
<Z LineEndCapStyle="NoAnchor" LineDrawStyle="Solid" Visible="False" RangeMin="0" LineColor="Black" RangeType="Automatic" TickmarkInterval="0" LineThickness="2" Extent="80" LogBase="10" RangeMax="0" TickmarkStyle="Percentage" TickmarkPercentage="10" NumericAxisType="Linear">
</Z>
<X LineEndCapStyle="NoAnchor" LineDrawStyle="Solid" Visible="False" RangeMin="0" LineColor="Black" RangeType="Automatic" TickmarkInterval="0" LineThickness="1" Extent="60" LogBase="10" RangeMax="0" TickmarkStyle="Percentage" TickmarkPercentage="10" NumericAxisType="Linear">
<Labels ItemFormatString="<ITEM_LABEL>" VerticalAlign="Center" WrapText="False" FontSizeBestFit="False" SeriesFormatString="<SERIES_LABEL>" ClipText="True" Font="Verdana, 7pt" Flip="False" ItemFormat="ItemLabel" FontColor="Black" Orientation="VerticalLeftFacing" Visible="True" OrientationAngle="0" HorizontalAlign="Near">
<SeriesLabels Font="Verdana, 7pt" Visible="True" HorizontalAlign="Center" FontSizeBestFit="False" ClipText="True" FormatString="<SERIES_LABEL>" Orientation="Horizontal" WrapText="False" Flip="False" FontColor="Black" VerticalAlign="Center" OrientationAngle="0"></SeriesLabels>
</X>
</Axis>
<TitleBottom Font="Microsoft Sans Serif, 7.8pt" Visible="False" Text="" FontSizeBestFit="False" Orientation="Horizontal" WrapText="False" Extent="26" FontColor="Black" HorizontalAlign="Far" VerticalAlign="Center" Location="Bottom">
</TitleBottom>
<TitleTop Font="Microsoft Sans Serif, 7.8pt" Visible="False" Text="" FontSizeBestFit="False" Orientation="Horizontal" WrapText="False" Extent="33" FontColor="Black" HorizontalAlign="Near" VerticalAlign="Center" Location="Top">
</TitleTop>
<DeploymentScenario Scenario="FileSystem" FilePath="ChartImages"></DeploymentScenario>
<Tooltips BorderThickness="1" Overflow="None" FormatString="<DATA_VALUE:00.##>" EnableFadingEffect="False" Format="DataValue" FontColor="Black" BorderColor="Black" Display="MouseMove" BackColor="AntiqueWhite" Padding="0"></Tooltips>
</igchart:UltraChart>
Problem: How do i change the colors from my rows in a barchartSolution 1: Change the color of 1 or more rows:
declare a public variable for the rows you want to invert(or change) the color of:
public List<int> invertedRows = new List<int>();
only add your eventhandler if the list has items:
if (invertedRows.Count > 0) { chart.ChartDrawItem += new Infragistics.UltraChart.Shared.Events.ChartDrawItemEventHandler(ultraChart1_ChartDrawItem); }
and the handler itself:
/// <summary> /// Eventhandler from chart.ChartDrawItem. /// For every int in invertedrows it will invert the row's color /// This only works for the first 4 columns. /// </summary> /// <Author>Twan Springeling</Author> /// <param name="sender"></param> /// <param name="e"></param> private void ultraChart1_ChartDrawItem(object sender, Infragistics.UltraChart.Shared.Events.ChartDrawItemEventArgs e) { Infragistics.UltraChart.Core.Primitives.Box box = e.Primitive as Infragistics.UltraChart.Core.Primitives.Box; if (box != null) { if (invertedRows.Contains(box.Row)) { switch(box.Column) { case 0: box.PE.Fill = System.Drawing.Color.FromArgb(215, 0, 5); box.PE.FillStopColor = System.Drawing.Color.FromArgb(215, 0, 5); break; case 1: box.PE.Fill = System.Drawing.Color.FromArgb(230, 190, 2); box.PE.FillStopColor = System.Drawing.Color.FromArgb(228, 188, 0); break; case 2: box.PE.Fill = System.Drawing.Color.FromArgb(7, 108, 176); box.PE.FillStopColor = System.Drawing.Color.FromArgb(0, 101, 169); break; case 3: box.PE.Fill = System.Drawing.Color.FromArgb(108, 162, 36); box.PE.FillStopColor = System.Drawing.Color.FromArgb(72, 126, 0); break; } } } }
Solution 2: Change your colormodel of your chart so all the rows will be changed
/// <summary> /// This will invert the colormodel of your barchart. /// Use this to set the colors to (in order): red, yellow, blue, green /// </summary> /// <Author>Twan Springeling</Author> /// <param name="ultrachart"></param> /// <returns></returns> public UltraChart invertdefaultcolor(UltraChart ultrachart) { System.Drawing.Color[ colorarray = { System.Drawing.Color.FromArgb(215, 0, 5), System.Drawing.Color.FromArgb(230, 190, 2), System.Drawing.Color.FromArgb(7, 108, 176), System.Drawing.Color.FromArgb(108, 162, 36) }; ultrachart.ColorModel.CustomPalette = colorarray; return ultrachart; }